question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
⌀
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
check-if-the-sentence-is-pangram
[ Go Solution ]Great explanation and Full Description
go-solution-great-explanation-and-full-d-iuhm
Intuition\nThe problem is asking us to determine if the input sentence is a pangram, i.e., it contains every letter of the alphabet at least once. To solve this
sansaian
NORMAL
2023-07-27T06:37:02.462235+00:00
2023-07-27T06:37:02.462257+00:00
92
false
# Intuition\nThe problem is asking us to determine if the input sentence is a pangram, i.e., it contains every letter of the alphabet at least once. To solve this problem, we can iterate through each character in the sentence and store each unique character in a data structure. If the total number of unique characters ...
3
0
['Hash Table', 'String', 'Go']
0
check-if-the-sentence-is-pangram
Easy Python solution
easy-python-solution-by-pavellver-bbig
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Pavellver
NORMAL
2023-03-31T09:03:14.199416+00:00
2023-03-31T09:03:14.199454+00:00
220
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['Python3']
0
check-if-the-sentence-is-pangram
easy
easy-by-bhavya32code-oef6
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Bhavya32code
NORMAL
2023-01-09T01:09:52.008340+00:00
2023-01-09T01:09:52.008381+00:00
119
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['C++']
0
check-if-the-sentence-is-pangram
Java Easy Solution
java-easy-solution-by-janhvi__28-vcj5
\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n Set<Character> set = new HashSet<Character>();\n int length = sentence.
Janhvi__28
NORMAL
2022-11-07T15:14:04.199315+00:00
2022-11-07T15:14:04.199361+00:00
469
false
```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n Set<Character> set = new HashSet<Character>();\n int length = sentence.length();\n for (int i = 0; i < length; i++) {\n char c = sentence.charAt(i);\n if (c >= \'a\' && c <= \'z\')\n s...
3
0
['Java']
0
check-if-the-sentence-is-pangram
0ms solution
0ms-solution-by-coding_menance-djoo
C++ code\n\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<short int> s(26);\n\n // add 1 to corresponding ascii i
coding_menance
NORMAL
2022-10-27T06:00:23.176129+00:00
2022-10-27T06:00:23.176180+00:00
49
false
# C++ code\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<short int> s(26);\n\n // add 1 to corresponding ascii indexes in vector\n for(char x:sentence) s[x-\'a\']++;\n\n // if any of the positions have 0, then that corresponding ascii character is missi...
3
0
['C++']
0
check-if-the-sentence-is-pangram
📌 Python solution using list
python-solution-using-list-by-vanderbilt-meae
\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n counter = [0 for _ in range(97, 123)]\n \n for i in sentence:\n
vanderbilt
NORMAL
2022-10-17T19:06:07.472215+00:00
2022-10-17T19:06:07.472262+00:00
1,086
false
```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n counter = [0 for _ in range(97, 123)]\n \n for i in sentence:\n counter[ord(i)-97] += 1\n \n for i in counter:\n if i == 0:\n return False\n return True\n```
3
0
['Array', 'Python', 'Python3']
0
check-if-the-sentence-is-pangram
Python solution using ASCII values
python-solution-using-ascii-values-by-am-6yjm
Here we are going to check the sentence with all 26 lower case english alphabets \n* chr(97) will be lowercase a so starting from there we will check whether ev
ambeersaipramod
NORMAL
2022-10-17T19:02:14.249600+00:00
2022-10-17T19:02:14.249639+00:00
82
false
* Here we are going to check the sentence with all 26 lower case english alphabets \n* `chr(97)` will be lowercase a so starting from there we will check whether every alphabet is there in the given sentence or not \n```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n for i in range(26):...
3
0
['Python', 'Python3']
0
check-if-the-sentence-is-pangram
✅Easy Java solution||HashSet||Beginner Friendly🔥
easy-java-solutionhashsetbeginner-friend-7mjh
If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries
deepVashisth
NORMAL
2022-10-17T18:57:57.022247+00:00
2022-10-17T18:57:57.022288+00:00
103
false
**If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries or some improvements please feel free to comment and share your views.**\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n ...
3
0
['Java']
0
check-if-the-sentence-is-pangram
C++ | Easy O(1) space complexity.
c-easy-o1-space-complexity-by-meteoroid-hfuy
Approach \nUsed int(32 bits) to update the occurence of characters. Since we know that total count will not be greater than 26. \n Describe your approach to sol
meteoroid
NORMAL
2022-10-17T17:29:23.110398+00:00
2022-10-18T11:17:00.178954+00:00
782
false
# Approach \nUsed int(32 bits) to update the occurence of characters. Since we know that total count will not be greater than 26. \n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Ad...
3
0
['C++']
2
check-if-the-sentence-is-pangram
Golang short solution
golang-short-solution-by-sansaian-txid
O(n) store O(n)\n\nfunc checkIfPangram(sentence string) bool {\n store:=make(map[rune]struct{})\n for _,ch:=range sentence{\n if _,ok:=store[ch];!o
sansaian
NORMAL
2022-10-17T16:48:29.051338+00:00
2022-10-17T16:48:29.051376+00:00
419
false
O(n) store O(n)\n```\nfunc checkIfPangram(sentence string) bool {\n store:=make(map[rune]struct{})\n for _,ch:=range sentence{\n if _,ok:=store[ch];!ok{\n store[ch]=struct{}{}\n }\n }\n return len(store)==26\n}\n```
3
0
['Go']
0
check-if-the-sentence-is-pangram
Easy java solution
easy-java-solution-by-siddhant_1602-69k1
Intuition\nCalculating the frequency of each alphabet \n Describe your first thoughts on how to solve this problem. \n\n# Approach\nStoring the frequency of eac
Siddhant_1602
NORMAL
2022-10-17T14:44:04.444035+00:00
2022-10-17T14:44:04.444285+00:00
83
false
# Intuition\nCalculating the frequency of each alphabet \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nStoring the frequency of each character and running a for loop to check whether if any character is missing or not\n<!-- Describe your approach to solving the problem. -->\n\n# Co...
3
0
['Hash Table', 'String', 'Java']
0
check-if-the-sentence-is-pangram
Character Traversal Simple solution
character-traversal-simple-solution-by-d-peog
Traverse from a to z, if any character not found in the String return false.\n\nAt the end return true.\n\n\npublic boolean checkIfPangram(String s) {\n
dsharma007
NORMAL
2022-10-17T12:22:20.062176+00:00
2022-10-17T12:22:20.062237+00:00
64
false
Traverse from `a to z`, if any character not found in the String return false.\n\nAt the end return true.\n\n```\npublic boolean checkIfPangram(String s) {\n \n for(char ch = \'a\'; ch <= \'z\'; ch++){\n if(s.indexOf(ch) == -1){\n return false;\n }\n }\n ...
3
0
['Java']
2
check-if-the-sentence-is-pangram
Easy Python | One-liner
easy-python-one-liner-by-tusharkhanna575-psqf
\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return(len(set(sentence))==26)\n
tusharkhanna575
NORMAL
2022-10-17T12:01:39.338844+00:00
2022-10-17T12:01:39.338877+00:00
302
false
```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return(len(set(sentence))==26)\n```
3
0
['Python', 'Python3']
0
check-if-the-sentence-is-pangram
📌C++ || 100% Runtime || Explained || ✅⭐⭐⭐
c-100-runtime-explained-by-luvchaudhary-60kb
\n# My simple and fast solution (beats 100% Runtime\uD83D\uDD25and 82.91% in memory)\n\n\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\
Luvchaudhary
NORMAL
2022-10-17T10:00:53.647237+00:00
2022-11-15T07:14:59.347487+00:00
1,295
false
\n# **My simple and fast solution (beats 100% Runtime\uD83D\uDD25and 82.91% in memory)**\n\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n int arr[26] = {0};\n\t\t//First traverse every letter of sentence in arr and increase its count if found\n for(int i=0; i<sentence.length...
3
0
['Array', 'C', 'C++']
3
check-if-the-sentence-is-pangram
3 line solution easy understanding c++ and unordered_map
3-line-solution-easy-understanding-c-and-4b7l
1 we declayer an unordered map of type \n2 loop through each letter in string and place it in unordered map\n3 if size of map is equal to 26 then all the letter
shivanantbhagat7
NORMAL
2022-10-17T08:28:30.804504+00:00
2022-10-17T08:28:30.804543+00:00
775
false
1 we declayer an unordered map of type <char,int>\n2 loop through each letter in string and place it in unordered map\n3 if size of map is equal to 26 then all the letters are included\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n unordered_map<char,int> mappa;\n for(int i=...
3
0
['C']
1
insertion-sort-list
An easy and clear way to sort ( O(1) space )
an-easy-and-clear-way-to-sort-o1-space-b-pcru
public ListNode insertionSortList(ListNode head) {\n \t\tif( head == null ){\n \t\t\treturn head;\n \t\t}\n \t\t\n \t\tListNode helper = new List
mingzixiecuole
NORMAL
2015-02-07T23:43:30+00:00
2018-10-23T22:39:00.622213+00:00
87,331
false
public ListNode insertionSortList(ListNode head) {\n \t\tif( head == null ){\n \t\t\treturn head;\n \t\t}\n \t\t\n \t\tListNode helper = new ListNode(0); //new starter of the sorted list\n \t\tListNode cur = head; //the node will be inserted\n \t\tListNode pre = helper; //insert node between pr...
413
12
['Java']
61
insertion-sort-list
Java / Python with Explanations
java-python-with-explanations-by-graceme-01g6
For example,\n\nGiven 1 -> 3 -> 2 -> 4 - > null\n\ndummy0 -> 1 -> 3 -> 2 -> 4 - > null\n | |\n ptr toInsert\n-- locate ptr = 3 by
gracemeng
NORMAL
2018-11-08T05:34:20.050070+00:00
2018-11-08T05:34:20.050134+00:00
12,416
false
For example,\n```\nGiven 1 -> 3 -> 2 -> 4 - > null\n\ndummy0 -> 1 -> 3 -> 2 -> 4 - > null\n | |\n ptr toInsert\n-- locate ptr = 3 by (ptr.val > ptr.next.val)\n-- locate toInsert = ptr.next\n\ndummy0 -> 1 -> 3 -> 2 -> 4 - > null\n | |\n toInsertPre toInsert\n-- locate...
150
0
[]
19
insertion-sort-list
Explained C++ solution (24ms)
explained-c-solution-24ms-by-jianchao-li-w319
Keep a sorted partial list (head) and start from the second node (head -> next), each time when we see a node with val smaller than its previous node, we scan f
jianchao-li
NORMAL
2015-05-27T15:45:36+00:00
2018-10-13T14:22:46.759816+00:00
29,006
false
Keep a sorted partial list (`head`) and start from the second node (`head -> next`), each time when we see a node with `val` smaller than its previous node, we scan from the `head` and find the position that the node should be inserted. Since a node may be inserted before `head`, we create a `dummy` head that points to...
146
2
['Linked List', 'C++']
27
insertion-sort-list
✅ [C++/Python/Java] 2 Simple Solution w/ Explanation | Swap values + Pointer Manipulation Approaches
cpythonjava-2-simple-solution-w-explanat-wapa
We need to sort the given linked list using insertion sort\n\n---\n\n\u2714\uFE0F Solution - I (Sort by Swapping Values)\n\nA pseudocode for standard insertion
archit91
NORMAL
2021-12-15T08:59:25.293036+00:00
2021-12-15T11:38:40.624307+00:00
7,171
false
We need to sort the given linked list using insertion sort\n\n---\n\n\u2714\uFE0F ***Solution - I (Sort by Swapping Values)***\n\nA **pseudocode for standard insertion sort** might look like this -\n\n```c\nfor i = 0 to n\n\tcur = A[i] and j = i - 1\n\twhile j >= 0 and arr[j] > cur:\n\t\tarr[j+1] = arr[j] ...
71
4
[]
6
insertion-sort-list
Clean Java solution using a fake head
clean-java-solution-using-a-fake-head-by-vv9x
public ListNode insertionSortList(ListNode head) {\n ListNode curr = head, next = null;\n // l is a fake head\n ListNode l = new ListNode(0);\n
jeantimex
NORMAL
2015-07-08T00:57:34+00:00
2018-09-03T02:14:14.160729+00:00
10,929
false
public ListNode insertionSortList(ListNode head) {\n ListNode curr = head, next = null;\n // l is a fake head\n ListNode l = new ListNode(0);\n \n while (curr != null) {\n next = curr.next;\n \n ListNode p = l;\n while (p.next != null && p.next.val < curr.val)\n ...
64
2
['Java']
9
insertion-sort-list
[Python3] 188ms Solution (explanation with visualization)
python3-188ms-solution-explanation-with-bo3az
Idea\n- Add dummy_head before head will help us to handle the insertion easily\n- Use two pointers\n\t- last_sorted: last node of the sorted part, whose value i
EckoTan0804
NORMAL
2021-04-25T21:01:14.655499+00:00
2021-04-25T21:06:18.334122+00:00
4,570
false
**Idea**\n- Add `dummy_head` before `head` will help us to handle the insertion easily\n- Use two pointers\n\t- `last_sorted`: last node of the sorted part, whose value is the largest of the sorted part\n\t- `cur`: next node of `last_sorted`, which is the current node to be considered\n\n\tAt the beginning, `last_sorte...
56
0
['Iterator', 'Python', 'Python3']
4
insertion-sort-list
Accepted Solution using JAVA
accepted-solution-using-java-by-isly-9rox
public class Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode helper=new ListNode(0);\n ListNode pre=helper;\n
isly
NORMAL
2014-06-06T11:40:35+00:00
2018-10-18T01:41:15.624340+00:00
13,940
false
public class Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode helper=new ListNode(0);\n ListNode pre=helper;\n ListNode current=head;\n while(current!=null) {\n pre=helper;\n while(pre.next!=null&&pre.next.val<current.val) {\n ...
43
2
[]
2
insertion-sort-list
C++ EASY TO SOLVE || Detailed Explanation with dry run
c-easy-to-solve-detailed-explanation-wit-jfiu
Intuition:-\nNothing for intuition this time. Since the question is loud and clear that we need to use insertion sort[Also explained in the description of the q
Cosmic_Phantom
NORMAL
2021-12-15T02:45:28.830071+00:00
2024-08-23T02:42:06.607182+00:00
6,894
false
**Intuition:-**\nNothing for intuition this time. Since the question is loud and clear that we need to use insertion sort[Also explained in the description of the question] for sorting the linked list .\n*A tip -Do not get intimidated by the length of code have faith in yourself that you can understand.*\n\n**Algorithm...
41
6
['Linked List', 'C', 'C++']
1
insertion-sort-list
[Python] Insertion Sort, explained
python-insertion-sort-explained-by-dbabi-xtqp
In this problem we are asked to implement insertion sort on singly-linked list data structure. And we do not really have a choice how to do it: we just need to
dbabichev
NORMAL
2020-11-02T08:49:30.255056+00:00
2020-11-02T08:49:30.255099+00:00
2,309
false
In this problem we are asked to implement insertion sort on singly-linked list data structure. And we do not really have a choice how to do it: we just need to apply definition of Insertion Sort. Imagine, that we already sorted some part of data, and we have something like:\n`1 2 3 7` **4** `6`,\nwhere by bold **4** I ...
40
1
[]
2
insertion-sort-list
AC Python 192ms solution
ac-python-192ms-solution-by-dietpepsi-0870
def insertionSortList(self, head):\n p = dummy = ListNode(0)\n cur = dummy.next = head\n while cur and cur.next:\n val = cur.nex
dietpepsi
NORMAL
2015-10-08T23:40:01+00:00
2018-08-14T05:23:27.851586+00:00
10,775
false
def insertionSortList(self, head):\n p = dummy = ListNode(0)\n cur = dummy.next = head\n while cur and cur.next:\n val = cur.next.val\n if cur.val < val:\n cur = cur.next\n continue\n if p.next.val > val:\n p = dummy\...
39
1
['Python']
8
insertion-sort-list
My C++ solution
my-c-solution-by-lxl-00jw
ListNode *insertionSortList(ListNode *head)\n {\n \tif (head == NULL || head->next == NULL)\n \t\treturn head;\n \n \tListNode *p = head->next;\n
lxl
NORMAL
2015-04-30T02:02:32+00:00
2018-08-21T19:41:24.545767+00:00
4,125
false
ListNode *insertionSortList(ListNode *head)\n {\n \tif (head == NULL || head->next == NULL)\n \t\treturn head;\n \n \tListNode *p = head->next;\n \thead->next = NULL;\n \n \twhile (p != NULL)\n \t{\n \t\tListNode *pNext = p->next; /*store the next node to be insert*/\n \t\tListNo...
31
0
[]
7
insertion-sort-list
Concise python solution with comments
concise-python-solution-with-comments-by-hafp
def insertionSortList(self, head):\n cur = dummy = ListNode(0)\n while head:\n if cur and cur.val > head.val: # reset pointer only when
zhuyinghua1203
NORMAL
2015-12-02T01:15:12+00:00
2015-12-02T01:15:12+00:00
4,822
false
def insertionSortList(self, head):\n cur = dummy = ListNode(0)\n while head:\n if cur and cur.val > head.val: # reset pointer only when new number is smaller than pointer value\n cur = dummy\n while cur.next and cur.next.val < head.val: # classic insertion sort to ...
27
1
['Python']
6
insertion-sort-list
7ms Java solution with explanation
7ms-java-solution-with-explanation-by-bd-ihim
The only real modification here is to take advantage of the ability to add to both the front and end of a linked list in constant time. A typical insertion sor
bdwalker
NORMAL
2016-03-15T17:53:14+00:00
2016-03-15T17:53:14+00:00
4,666
false
The only real modification here is to take advantage of the ability to add to both the front and end of a linked list in constant time. A typical insertion sort would have to go through the entire array to find the new location to insert the element. If the element should be placed first in the array then we have to s...
23
0
[]
2
insertion-sort-list
Python time limit is too tight
python-time-limit-is-too-tight-by-yintao-6ec8
I have basically the same code in python and java (see below). python got TLE, but java was accepted. I propose to relax the python time limit a little bit.\n\n
yintaosong
NORMAL
2014-11-09T18:48:11+00:00
2018-08-22T17:54:01.803720+00:00
5,904
false
I have basically the same code in python and java (see below). python got TLE, but java was accepted. I propose to relax the python time limit a little bit.\n\n**Python**\n\n class Solution:\n # @param head, a ListNode\n # @return a ListNode\n def insertionSortList(self, head):\n srt = None\n ...
22
1
[]
7
insertion-sort-list
C++ recursive insertion sort.
c-recursive-insertion-sort-by-oldcodingf-uc5j
\n ListNode* insertionSortList(ListNode* head) {\n if (head == nullptr || head->next == NULL)\n return head;\n ListNode *h = ins
oldcodingfarmer
NORMAL
2015-12-06T19:05:30+00:00
2015-12-06T19:05:30+00:00
2,123
false
\n ListNode* insertionSortList(ListNode* head) {\n if (head == nullptr || head->next == NULL)\n return head;\n ListNode *h = insertionSortList(head->next);\n if (head->val <= h->val) { // first case\n head->next = h;\n return head;\n }\n Li...
16
0
['Recursion', 'C++']
0
insertion-sort-list
✔️ 100% Fastest Swift Solution, time: O(n log n), space: O(n).
100-fastest-swift-solution-time-on-log-n-ed48
\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() {
sergeyleschev
NORMAL
2022-04-13T05:52:48.516100+00:00
2022-04-13T05:53:23.228567+00:00
855
false
```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { se...
14
0
['Swift']
1
insertion-sort-list
C++ Simple and Short Explained Solution, No Extra Space
c-simple-and-short-explained-solution-no-rymg
Idea:\nWe start the new sorted list with a zero node, so that it will be easier to insert in every position.\nWe iterate through the list with the head pointer.
yehudisk
NORMAL
2021-12-15T07:17:48.837292+00:00
2021-12-15T07:17:48.837328+00:00
1,182
false
**Idea:**\nWe start the new sorted list with a zero node, so that it will be easier to insert in every position.\nWe iterate through the list with the `head` pointer.\nFor each node, we use the function `insert` to iterate through the new sorted list and find the right insertion position.\nWe return `new_head->next` be...
13
2
['C']
1
insertion-sort-list
✔️ [Python3] INSERTION SORT, Explained
python3-insertion-sort-explained-by-arto-al08
The idea is to create a dummy node that would be the head of the sorted part of the list. Iterate over the given list and one by one add nodes to the sorted lis
artod
NORMAL
2021-12-15T01:12:45.244091+00:00
2021-12-15T03:56:50.805258+00:00
2,782
false
The idea is to create a dummy node that would be the head of the sorted part of the list. Iterate over the given list and one by one add nodes to the sorted list at the appropriate place following the insertion sort algorithm.\n\nTime: **O(n^2)**\nSpace: **O(1)**\n\nRuntime: 1677 ms, faster than **51.65%** of Python3 o...
13
5
['Python3']
2
insertion-sort-list
[C++] Pointer-based Solution Explained, 100% Time, 90% Space
c-pointer-based-solution-explained-100-t-u241
Ah, gotta love starting the day with classic algorithms you otherwise would just see again on textbooks and manuals :)\n\nIn order to proceed with this one, we
ajna
NORMAL
2020-11-02T10:19:28.641842+00:00
2020-11-02T10:19:28.641873+00:00
1,761
false
Ah, gotta love starting the day with classic algorithms you otherwise would just see again on textbooks and manuals :)\n\nIn order to proceed with this one, we need to first of all check if we are dealing with an empty list: if so, we just return `NULL`.\n\nOtherwise, we create 3 support variables, all `ListNode` point...
12
2
['Graph', 'C', 'C++']
0
insertion-sort-list
Concise JavaScript solution
concise-javascript-solution-by-linfongi-rzgh
function insertionSortList(head) {\n var before = { val: -Number.MAX_VALUE, next: null };\n \n while (head) {\n var prev = befor
linfongi
NORMAL
2016-06-04T03:47:12+00:00
2016-06-04T03:47:12+00:00
1,039
false
function insertionSortList(head) {\n var before = { val: -Number.MAX_VALUE, next: null };\n \n while (head) {\n var prev = before;\n \n // find prev\n while (prev.next && prev.next.val < head.val) {\n prev = prev.next;\n }\n ...
12
0
[]
2
insertion-sort-list
147: Solution with step by step explanation
147-solution-with-step-by-step-explanati-pyo3
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThe solution involves iterating through the linked list, removing each no
Marlen09
NORMAL
2023-02-19T16:56:32.519211+00:00
2023-02-19T16:56:32.519257+00:00
2,817
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThe solution involves iterating through the linked list, removing each node from the list, and then inserting it into the sorted portion of the list. The sorted portion of the list is initially just the first node, and grows...
11
0
['Linked List', 'Sorting', 'Python', 'Python3']
0
insertion-sort-list
✅ [Python] Dummy Head || Clean and Easy to Understand with Detailed Explanation
python-dummy-head-clean-and-easy-to-unde-9pgv
Time Complexity : O(N2) \nSpace Complexity : O(1)\nDummy head can make the code more concise\n\nclass Solution(object):\n def insertionSortList(self, head):\
linfq
NORMAL
2021-12-15T03:34:05.073794+00:00
2021-12-15T03:46:00.283987+00:00
756
false
**Time Complexity : O(N<sup>2</sup>) \nSpace Complexity : O(1)**\n**Dummy head can make the code more concise**\n```\nclass Solution(object):\n def insertionSortList(self, head):\n p, sl = head, ListNode() # sl is the sortedList with dummy head node.\n while p: # traverse the input linked list until ...
11
3
['Python']
1
insertion-sort-list
[Python] Actual Insertion Sort (solution article has inaccurate implementation)
python-actual-insertion-sort-solution-ar-x3el
Strictly speaking, in insertion sort, the intermeidate sorted list is iterated backwards (we first compare the new item with the last item and swap if they are
dadagda
NORMAL
2021-12-15T01:23:07.398475+00:00
2021-12-15T01:23:07.398513+00:00
650
false
Strictly speaking, in insertion sort, the intermeidate sorted list is iterated backwards (we first compare the new item with the last item and swap if they are out of order: this is repeated until new item is in order with previous item)\nHowever, in the solution article and some other posts, the intermediate sorted li...
11
0
[]
5
insertion-sort-list
Simple and clean java code
simple-and-clean-java-code-by-jinwu-8jyi
public ListNode insertionSortList(ListNode head) {\n\t\tListNode cur = head;\n\t\tListNode dummy = new ListNode(0), p;\n\t\twhile (cur != null) {\n\t\t\t//locat
jinwu
NORMAL
2015-09-24T05:54:59+00:00
2015-09-24T05:54:59+00:00
2,934
false
public ListNode insertionSortList(ListNode head) {\n\t\tListNode cur = head;\n\t\tListNode dummy = new ListNode(0), p;\n\t\twhile (cur != null) {\n\t\t\t//locate the insertion position.\n\t\t\tp = dummy;\n\t\t\twhile (p.next != null && cur.val > p.next.val) {\n\t\t\t\tp = p.next;\n\t\t\t}\n\t\t\t//insert between p...
11
1
['Java']
4
insertion-sort-list
✅💯🔥Simple Code🚀📌|| 🔥✔️Easy to understand🎯 || 🎓🧠Insertion Logical🔥|| Beginner friendly💀💯
simple-code-easy-to-understand-insertion-69i2
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
atishayj4in
NORMAL
2024-07-27T20:51:05.028180+00:00
2024-08-01T19:51:48.573517+00:00
2,080
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
10
0
['Linked List', 'C', 'Sorting', 'Python', 'C++', 'Java']
0
insertion-sort-list
For God's sake, don't try sorting a linked list during the interview
for-gods-sake-dont-try-sorting-a-linked-5bzi4
\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n vector<int> nums;\n ListNode* temp = head;\n while(temp !=
vaibhav4859
NORMAL
2021-12-15T11:59:16.695892+00:00
2021-12-15T11:59:16.695954+00:00
858
false
```\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n vector<int> nums;\n ListNode* temp = head;\n while(temp != NULL){\n nums.push_back(temp->val);\n temp = temp->next;\n }\n \n sort(nums.begin(), nums.end());\n temp =...
9
0
['Linked List', 'C', 'C++']
0
insertion-sort-list
easy to understand
easy-to-understand-by-shrivastava123-sua0
\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val)
shrivastava123
NORMAL
2020-11-02T13:06:37.064526+00:00
2020-11-02T13:06:37.064565+00:00
848
false
```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode inserti...
9
0
['Java']
1
insertion-sort-list
Short, simple and fast c++ solution. No need for a dummy or similar to handle the new head creation.
short-simple-and-fast-c-solution-no-need-mrka
A lot of solutions allocate a dummy node with the intensions of using the dummy.next to point to the head of the new list. It\'s much simpler to instead use a p
christrompf
NORMAL
2018-07-16T15:39:31.944729+00:00
2024-07-10T11:05:04.974539+00:00
638
false
A lot of solutions allocate a dummy node with the intensions of using the dummy.next to point to the head of the new list. It\'s much simpler to instead use a pointer to a pointer that stores the address of either the pointer to the new head or the next pointer of the previous node. That way an update to whichever poin...
9
1
['C', 'C++']
0
insertion-sort-list
My C++ solution by using pointer's pointer to do insertion.
my-c-solution-by-using-pointers-pointer-nk0c7
Short and easy way to manipulate the list.\n \n\n class Solution {\n public:\n ListNode insertionSortList(ListNode head) {\n ListNode no
beeender
NORMAL
2014-12-10T14:48:53+00:00
2014-12-10T14:48:53+00:00
2,178
false
Short and easy way to manipulate the list.\n \n\n class Solution {\n public:\n ListNode *insertionSortList(ListNode *head) {\n ListNode **node = &head;\n while ((*node)) {\n bool flag = false;\n for (ListNode **cmp=&head; *cmp!=*node; cmp=&(*cmp)->next) {...
8
0
[]
3
insertion-sort-list
Easy To Understand code Of " insertion-sort-list"
easy-to-understand-code-of-insertion-sor-l820
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
saurabh77008
NORMAL
2023-03-05T12:51:57.405739+00:00
2023-03-05T12:51:57.405766+00:00
1,231
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
7
0
['Linked List', 'Math', 'Sorting', 'Java']
1
insertion-sort-list
Simple Solution with step by step explaination
simple-solution-with-step-by-step-explai-aq61
In this question, we have to perform insertion sorting on a linked list.\nTherefore, to first understand this, we first need to know about Insertion sort.\nIn I
paramsahai25
NORMAL
2023-01-18T07:22:27.319832+00:00
2023-01-18T07:22:27.319871+00:00
990
false
In this question, we have to perform insertion sorting on a linked list.\nTherefore, to first understand this, we first need to know about Insertion sort.\nIn Insertion Sort, the array (linked list in this case) is divided into two parts, the unsorted and sorted parts.\n\nElements from unsorted part are picked and plac...
7
0
['C']
1
insertion-sort-list
[Python] Clean & Concise - Time O(n^2), Space O(1)
python-clean-concise-time-on2-space-o1-b-ifvj
python\nclass Solution(object):\n def insertionSortList(self, head):\n dummyHead= ListNode(0)\n \n def insert(head):\n prev =
hiepit
NORMAL
2020-11-03T07:19:27.455852+00:00
2020-11-03T07:19:27.455903+00:00
268
false
```python\nclass Solution(object):\n def insertionSortList(self, head):\n dummyHead= ListNode(0)\n \n def insert(head):\n prev = dummyHead\n curr = dummyHead.next\n while curr and curr.val <= head.val:\n prev = curr\n curr = curr.nex...
7
1
[]
1
insertion-sort-list
[recommend for beginners]clean C++ implementation with detailed explaination
recommend-for-beginnersclean-c-implement-65ux
This problem is all about details, you just need to check what to do when insert the cur-pointer to the linked-list.\n\nYou need to consider 2 cases carefully.
rainbowsecret
NORMAL
2016-01-17T15:08:33+00:00
2016-01-17T15:08:33+00:00
1,454
false
This problem is all about details, you just need to check what to do when insert the cur-pointer to the linked-list.\n\nYou need to consider 2 cases carefully. I believe it is all about details.\n\n class Solution {\n public:\n ListNode* insertionSortList(ListNode* head) {\n if(!head) return ...
7
1
[]
2
insertion-sort-list
✔️ 100% Fastest TypeScript Solution
100-fastest-typescript-solution-by-serge-xjsj
\n/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: Lis
sergeyleschev
NORMAL
2022-03-29T05:01:30.562192+00:00
2022-03-30T16:41:33.061682+00:00
1,118
false
```\n/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction ...
6
0
['TypeScript', 'JavaScript']
0
insertion-sort-list
insertion Sort List - 100%
insertion-sort-list-100-by-abhishekjha78-i7wf
class Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode prev = head;\n ListNode curr = prev.next;\n \n i
abhishekjha786
NORMAL
2021-12-15T08:50:45.749703+00:00
2021-12-15T08:50:45.749730+00:00
165
false
class Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode prev = head;\n ListNode curr = prev.next;\n \n if(head==null || head.next==null) \n return head;\n \n while(curr != null) {\n if(curr.val < prev.val) {\n pre...
6
1
['Linked List']
1
insertion-sort-list
C++
c-by-ahmedmohamedd-5a9o
\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n *
ahmedmohamedd
NORMAL
2020-11-02T08:54:21.688924+00:00
2020-11-02T08:54:21.688971+00:00
696
false
```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n List...
6
0
[]
3
insertion-sort-list
One way to accept in python against TLE
one-way-to-accept-in-python-against-tle-465z9
My original code is very intuitive. I checked each unsorted element one by one and added it into sorted part. The way I added it is that I check from the head t
ideno
NORMAL
2014-07-13T05:10:32+00:00
2014-07-13T05:10:32+00:00
2,654
false
My original code is very intuitive. I checked each unsorted element one by one and added it into sorted part. The way I added it is that I check from the head to tailer of the sorted part. Here is my original code in python and off-line test for 2000 data costs 2.3s while the result is TLE for on-line test.\n\n clas...
6
0
['Python']
3
insertion-sort-list
10 line clean and easy-to-understand C++ solution
10-line-clean-and-easy-to-understand-c-s-zz9e
Please see [my blog post][1] for more.\n\n ListNode insertionSortList(ListNode head) {\n ListNode dummy(INT_MIN);\n ListNode prev, cur, *next;\
xiaohui7
NORMAL
2015-03-31T15:49:59+00:00
2015-03-31T15:49:59+00:00
1,104
false
Please see [my blog post][1] for more.\n\n ListNode *insertionSortList(ListNode *head) {\n ListNode dummy(INT_MIN);\n ListNode *prev, *cur, *next;\n \n for (auto p = head; p; p = next) {\n next = p->next;\n // invariant: list headed by dummy.next is sorted\n ...
6
1
['Linked List', 'Sorting']
0
insertion-sort-list
Maybe the best JAVA solution with code comments
maybe-the-best-java-solution-with-code-c-o7n4
public class Solution {\n \n public ListNode insertionSortList(ListNode head) {\n if(head == null || head.next == null){\n r
zwangbo
NORMAL
2015-01-29T06:41:29+00:00
2015-01-29T06:41:29+00:00
2,363
false
public class Solution {\n \n public ListNode insertionSortList(ListNode head) {\n if(head == null || head.next == null){\n return head;\n }\n //record node before insertNode\n ListNode preNode = head;\n //rocord node need to be inserted...
6
1
['Java']
2
insertion-sort-list
💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 100
easiestfaster-lesser-cpython3javacpython-2pc8
Intuition\n\n\n\n\n\n\n\n\njavascript []\n//JavaScript Code\n/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (v
Edwards310
NORMAL
2024-08-27T16:41:12.469021+00:00
2024-08-27T16:41:12.469061+00:00
2,270
false
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/221504d7-50c3-4224-8703-e525a2fdf672_1724776353.854879.jpeg)\n![Screenshot 2024-08-27 124040.png](https://assets.leetcode.com/users/images/17c345ea-44ce-43b0-83b5-c26e4e3e5024_1724776363.6431353.png)\n![Screenshot 2024-08-27 175324.png](https://...
5
1
['Linked List', 'C', 'Sorting', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#']
5
insertion-sort-list
using Bubble sort in C
using-bubble-sort-in-c-by-shaik_moinuddi-x3zd
Intuition\njust use the bubble sort.the only difference is u need to reset the pointer to point head after the completation of second loop and in second loop u
Shaik_Moinuddin73
NORMAL
2023-07-12T14:50:55.688681+00:00
2023-08-12T14:42:15.363946+00:00
808
false
# Intuition\njust use the bubble sort.the only difference is u need to reset the pointer to point head after the completation of second loop and in second loop u need to swap two values if one val is greater than another.then update temp pointer to its next\n\n# Approach\n<!-- Describe your approach to solving the prob...
5
0
['Linked List', 'C', 'Sorting']
2
insertion-sort-list
Simple Solution || O(N^2) time || O(1) space
simple-solution-on2-time-o1-space-by-shr-1jzx
\n\n# Code\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullpt
Shristha
NORMAL
2023-01-28T11:51:12.885065+00:00
2023-01-28T11:51:12.885099+00:00
680
false
\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npubli...
5
0
['Sorting', 'C++']
0
insertion-sort-list
simple c++ clean solution
simple-c-clean-solution-by-dhiraj121-fsos
class Solution {\npublic:\n\n ListNode insertionSortList(ListNode head) {\n ListNode nxt = head -> next;\n while(nxt != NULL)\n {\n
Dhiraj121
NORMAL
2022-08-30T04:55:58.369157+00:00
2022-08-30T04:55:58.369184+00:00
942
false
class Solution {\npublic:\n\n ListNode* insertionSortList(ListNode* head) {\n ListNode *nxt = head -> next;\n while(nxt != NULL)\n {\n ListNode *curr = head;\n while(curr != nxt)\n {\n if(nxt -> val < curr -> val)\n swap(curr -> ...
5
0
['Linked List', 'C']
2
insertion-sort-list
C++ | In-Place Insertion Sort
c-in-place-insertion-sort-by-apartida-mx7b
I sorted the given list in-place since the problem didn\'t specify producing a new list.\n```\n ListNode insertionSortList(ListNode head) {\n \n
apartida
NORMAL
2021-12-15T20:11:14.082223+00:00
2021-12-15T20:11:14.082279+00:00
378
false
I sorted the given list in-place since the problem didn\'t specify producing a new list.\n```\n ListNode* insertionSortList(ListNode* head) {\n \n /* Base case */\n if (head == nullptr) return nullptr; \n \n /* Perform in-place insertion sort. */\n /* Time - O(n^2); Space - ...
5
0
['C']
1
insertion-sort-list
Python Solution Explained (video + code)
python-solution-explained-video-code-by-wtoia
\nhttps://www.youtube.com/watch?v=-0w2uswTST8\n\nclass Solution:\n def insertionSortList(self, head: ListNode) -> ListNode:\n dummy_head = ListNode()\
spec_he123
NORMAL
2020-11-02T17:48:46.952719+00:00
2020-11-02T17:48:46.952752+00:00
509
false
[](https://www.youtube.com/watch?v=-0w2uswTST8)\nhttps://www.youtube.com/watch?v=-0w2uswTST8\n```\nclass Solution:\n def insertionSortList(self, head: ListNode) -> ListNode:\n dummy_head = ListNode()\n curr = head\n \n while curr:\n prev_pointer = dummy_head\n next_p...
5
0
['Linked List', 'Python', 'Python3']
0
insertion-sort-list
A short and clear c++ solution.
a-short-and-clear-c-solution-by-dikea-1vkg
c++\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n if(!head) return NULL;\n ListNode *res = new ListNode(0);\n
dikea
NORMAL
2019-07-06T13:29:04.036146+00:00
2019-07-06T13:29:18.470559+00:00
188
false
```c++\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n if(!head) return NULL;\n ListNode *res = new ListNode(0);\n while(head) {\n ListNode* p = res->next;\n ListNode* pre = res;\n while(p && head->val > p->val) {\n pre...
5
0
[]
0
insertion-sort-list
Solution in C
solution-in-c-by-joshua_duan-a2kz
Code\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nstruct ListNode* insertion
joshua_duan
NORMAL
2024-03-21T06:14:47.381692+00:00
2024-03-21T06:14:47.381723+00:00
693
false
# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nstruct ListNode* insertionSortList(struct ListNode* head) {\n if (!head || !head->next) {\n return head;\n }\n\n struct ListNode* dummy = malloc(sizeof(struct ListNo...
4
0
['C']
1
insertion-sort-list
Insertion Sort || JAVA Easy Solution
insertion-sort-java-easy-solution-by-saa-usok
Explanation:\n\n1. Initialization:\n - A dummy node is created at the beginning to simplify the insertion process. The dummy node\'s next points to the sorted
saad_hussain_
NORMAL
2024-02-29T18:35:57.466463+00:00
2024-02-29T18:35:57.466484+00:00
744
false
### Explanation:\n\n1. **Initialization:**\n - A dummy node is created at the beginning to simplify the insertion process. The dummy node\'s `next` points to the sorted list.\n - `current` is a pointer initialized to the head of the original linked list.\n\n2. **Iterative Sorting:**\n - The algorithm iterates thr...
4
0
['Linked List', 'Java']
0
insertion-sort-list
Easy Solution || Beats 96.63% of users with C++
easy-solution-beats-9663-of-users-with-c-ohs9
Upvote\n\n# Code\n\n\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n vector<int>v;\n while(head!=NULL){\n
007anshuyadav
NORMAL
2024-01-21T08:53:03.531168+00:00
2024-01-21T08:53:03.531199+00:00
766
false
# Upvote\n\n# Code\n```\n\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n vector<int>v;\n while(head!=NULL){\n v.push_back(head->val);\n head=head->next;\n\n }\n sort(v.begin(),v.end());\n ListNode* temp=new ListNode(0);\n ListNod...
4
0
['Linked List', 'Sorting', 'C++']
3
insertion-sort-list
Exact similar code to insertion sort in the array easy to understand
exact-similar-code-to-insertion-sort-in-0um7p
I request you dry run once on the first exapmle itself and you will understand \njust igonre the cout<val;\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Spac
akshansh_
NORMAL
2024-01-13T16:19:08.264383+00:00
2024-01-13T16:19:08.264413+00:00
523
false
I request you dry run once on the first exapmle itself and you will understand \njust igonre the cout<<head->val;\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Space complexity:\nO(1)\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * Lis...
4
0
['C++']
2
insertion-sort-list
Clearest Go Solution
clearest-go-solution-by-evleria-w3i5
Github link\n\n\nfunc insertionSortList(head *ListNode) *ListNode {\n\tdummy := new(ListNode)\n\tfor head != nil {\n\t\tcur := dummy\n\t\tfor ; cur.Next != nil
evleria
NORMAL
2021-12-15T19:33:04.237157+00:00
2021-12-15T19:33:04.237192+00:00
449
false
[Github link](https://github.com/evleria/leetcode-in-go/blob/main/problems/0147-insertion-sort-list/insertion_sort_list.go)\n\n```\nfunc insertionSortList(head *ListNode) *ListNode {\n\tdummy := new(ListNode)\n\tfor head != nil {\n\t\tcur := dummy\n\t\tfor ; cur.Next != nil && cur.Next.Val < head.Val; cur = cur.Next {\...
4
0
['Go']
1
insertion-sort-list
2 Implementation | Explained
2-implementation-explained-by-sunny_38-qzx1
Idea?\n We need to sort the list using Insertion Sort.\n Insertion Sort works in O(n^2) time, each time picking up the new element and inserting back this eleme
sunny_38
NORMAL
2021-12-15T05:59:28.258192+00:00
2021-12-15T06:01:58.659300+00:00
214
false
**Idea?**\n* We need to sort the list using Insertion Sort.\n* Insertion Sort works in **O(n^2) time**, each time picking up the new element and **inserting back this element** at the correct position in the sorted list found till now.\n\n**Implementation 1:-(Not Efficient)**\n* Each time when we pick up the new elemen...
4
0
[]
0
insertion-sort-list
Java two solutions - Pointer change and Value change
java-two-solutions-pointer-change-and-va-v8kn
Pointer change\n\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode dummy = new ListNode(0);\n ListNode curr
vinsinin
NORMAL
2020-12-31T21:32:43.679149+00:00
2020-12-31T21:32:43.679195+00:00
387
false
**Pointer change**\n```\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode dummy = new ListNode(0);\n ListNode curr = head;\n \n while (curr != null){\n ListNode prev = dummy;\n \n while (prev.next != null && prev.next.v...
4
0
['Java']
1
insertion-sort-list
[Java] JAVA 8 STREAM API
java-java-8-stream-api-by-kostrych_artem-u3ah
\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n\t\tList<ListNode> listNodes = new LinkedList<>();\n\t\twhile (head!=null)\n\t\t{\n\
kostrych_artem
NORMAL
2020-11-02T08:00:26.540932+00:00
2020-11-02T08:00:26.540980+00:00
144
false
```\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n\t\tList<ListNode> listNodes = new LinkedList<>();\n\t\twhile (head!=null)\n\t\t{\n\t\t\tlistNodes.add(head);\n\t\t\thead=head.next;\n\t\t}\n\t\tlistNodes=listNodes.stream().sorted(Comparator.comparingInt(node -> node.val)).collect(Collector...
4
1
[]
0
insertion-sort-list
Python3 & Java 4 pointers solution
python3-java-4-pointers-solution-by-meiy-0f7g
\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\ncl
meiyaowen
NORMAL
2020-08-20T01:20:03.144762+00:00
2020-08-20T01:52:11.709120+00:00
440
false
```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def insertionSortList(self, head: ListNode) -> ListNode:\n # if head is empty or only have 1 element, return head\n if not h...
4
0
['Java', 'Python3']
1
insertion-sort-list
[Rust]
rust-by-qini8-6ccs
\nimpl Solution {\n pub fn insertion_sort_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {\n let mut head = head;\n let mut new_hea
qini8
NORMAL
2019-12-15T08:27:08.717456+00:00
2019-12-15T08:27:08.717501+00:00
136
false
```\nimpl Solution {\n pub fn insertion_sort_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {\n let mut head = head;\n let mut new_head = ListNode::new(0);\n while let Some(mut boxed) = head.take() {\n head = boxed.next.take();\n let mut ptr = &mut new_head;\n ...
4
0
[]
2
insertion-sort-list
[[[ C++ ]]] Top 80% O(N) With O(1) Memory - Slick Rick Solution [[KoDerZ KamP]]
c-top-80-on-with-o1-memory-slick-rick-so-lv8j
\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n \n //We will store the solution after sentinel..\n ListNod
nraptis
NORMAL
2019-07-06T02:39:07.860722+00:00
2019-07-06T02:39:07.860753+00:00
123
false
```\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n \n //We will store the solution after sentinel..\n ListNode *aSentinel = new ListNode(0);\n ListNode *aPrev = NULL;\n \n //We pluck nodes out from the original list, one at a time.\n List...
4
0
[]
0
insertion-sort-list
3 ms Java solution without recursive
3-ms-java-solution-without-recursive-by-0ulez
public ListNode insertionSortList(ListNode head) {\n \n\t\tif(head == null || head.next == null) {\n return head;\n } \n Li
swetchha
NORMAL
2019-04-04T17:09:40.414620+00:00
2019-04-04T17:09:40.414743+00:00
232
false
public ListNode insertionSortList(ListNode head) {\n \n\t\tif(head == null || head.next == null) {\n return head;\n } \n ListNode newHead = new ListNode(0);\n newHead.next = head;\n \n while(head.next != null) {\n if (head.val > head.next.val) {\n ...
4
0
[]
0
insertion-sort-list
Share my C++ solution
share-my-c-solution-by-yunhua-iwbx
It is quite easy if you swap value instead of pointer. check my insertionSortListV. Once you understand the "swap by value" version. then "swap by pointer" is e
yunhua
NORMAL
2014-09-26T03:04:35+00:00
2014-09-26T03:04:35+00:00
1,421
false
It is quite easy if you swap value instead of pointer. check my insertionSortListV. Once you understand the "swap by value" version. then "swap by pointer" is easy too. check insertionSortListP.\n\n1. pi means pre-i. like this: A1->A2->pj->j->A5->A6-pi->i->... the 3 steps to swap i and j by pointer \n\n SWAP(pi...
4
1
[]
2
insertion-sort-list
Java iterative and recursive solutions.
java-iterative-and-recursive-solutions-b-wq07
\n // iteratively\n public ListNode insertionSortList(ListNode head) {\n if (head == null || head.next == null) {\n return head;\n
oldcodingfarmer
NORMAL
2016-05-01T06:49:53+00:00
2016-05-01T06:49:53+00:00
709
false
\n // iteratively\n public ListNode insertionSortList(ListNode head) {\n if (head == null || head.next == null) {\n return head;\n }\n ListNode p, dummy = new ListNode(0), node = head;\n dummy.next = head;\n while (node.next != null) {\n if (node.va...
4
0
['Recursion', 'Iterator', 'Java']
1
insertion-sort-list
simple python solution
simple-python-solution-by-pengshuang-9mde
'''\nclass Solution(object):\n \n def insertionSortList(self, head):\n """\n :type head: ListNode\n :rtype: ListNode\n """\n
pengshuang
NORMAL
2016-09-03T01:36:43.513000+00:00
2016-09-03T01:36:43.513000+00:00
608
false
'''\nclass Solution(object):\n \n def insertionSortList(self, head):\n """\n :type head: ListNode\n :rtype: ListNode\n """\n if not head:\n return head\n dummy = ListNode(0)\n dummy.next = head\n curr = head\n while curr.next:\n ...
4
0
[]
0
insertion-sort-list
Clear JavaScript solution
clear-javascript-solution-by-loctn-qurx
\nvar insertionSortList = function(head) {\n if (!head) return null;\n let sorted = head;\n head = head.next;\n sorted.next = null;\n while (head
loctn
NORMAL
2017-03-26T19:04:40.253000+00:00
2017-03-26T19:04:40.253000+00:00
1,222
false
```\nvar insertionSortList = function(head) {\n if (!head) return null;\n let sorted = head;\n head = head.next;\n sorted.next = null;\n while (head) {\n let prev = null;\n let node = sorted;\n while (node && head.val > node.val) {\n prev = node;\n node = node.n...
4
0
['JavaScript']
0
insertion-sort-list
CPP || best in the world
cpp-best-in-the-world-by-apoorvjain7222-l7yl
Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n# Code
apoorvjain7222
NORMAL
2024-10-14T18:33:53.385305+00:00
2024-10-14T18:33:53.385333+00:00
684
false
# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(...
3
0
['Linked List', 'Sorting', 'C++']
1
insertion-sort-list
Beginner Friendly using sorting in o(1) space
beginner-friendly-using-sorting-in-o1-sp-ci9t
\n# Approach\nCreating a new linkedlist using insertion sotr\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\n/**\n * Definit
Aman_8808_Singh
NORMAL
2024-01-11T09:31:06.656418+00:00
2024-01-11T09:33:31.999979+00:00
813
false
\n# Approach\nCreating a new linkedlist using insertion sotr\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int...
3
0
['Linked List', 'C++']
0
insertion-sort-list
Simple Java Solution True Insertion Sort
simple-java-solution-true-insertion-sort-5lgu
Intuition\nSplit into two lists. Take from unsorted list and insert into sorted list.\n\n# Approach\nSame as intuition \xAF\\(\u30C4)/\xAF\n\n# Complexity\n- Ti
SnowmanTheCold
NORMAL
2023-08-25T07:31:31.479751+00:00
2023-08-25T17:20:18.260754+00:00
815
false
# Intuition\nSplit into two lists. Take from unsorted list and insert into sorted list.\n\n# Approach\nSame as intuition \xAF\\\\_(\u30C4)_/\xAF\n\n# Complexity\n- Time complexity: O(n^2)\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ...
3
0
['Java']
1
insertion-sort-list
C++ | Insertion sort | Easy Solution
c-insertion-sort-easy-solution-by-deepak-byk8
\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n#
godmode_2311
NORMAL
2023-03-15T17:34:16.650005+00:00
2023-03-15T17:34:16.650051+00:00
1,469
false
\n# Complexity\n- Time complexity:`O(n)`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:`O(n)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n \n // if list contains only on...
3
0
['Linked List', 'Sorting', 'C++']
1
insertion-sort-list
Java || Easiest Approach || Explained || 3 pointers || O(1) space soln
java-easiest-approach-explained-3-pointe-aam5
```\nclass Solution {\n \n public ListNode insertionSortList(ListNode head) {\n //making a dummy node to avoid edge cases\n ListNode dummy =
kurmiamreet44
NORMAL
2023-01-24T13:01:43.802911+00:00
2023-01-24T18:53:08.908065+00:00
883
false
```\nclass Solution {\n \n public ListNode insertionSortList(ListNode head) {\n //making a dummy node to avoid edge cases\n ListNode dummy = new ListNode(-1);\n // prev moves from starting to value who is just lesser than the next.val\n ListNode prev = dummy;\n // we use it to ...
3
0
['Java']
0
insertion-sort-list
JAVA solutions
java-solutions-by-infox_92-4sdq
\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode dummy = new ListNode(0, head);\n \n ListNode prev = h
Infox_92
NORMAL
2022-11-06T08:50:46.486557+00:00
2022-11-06T08:50:46.486582+00:00
1,608
false
```\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode dummy = new ListNode(0, head);\n \n ListNode prev = head;\n ListNode curr = head.next;\n \n while (curr != null) {\n if (curr.val >= prev.val) {\n prev = curr;\n ...
3
0
['Java', 'JavaScript']
2
insertion-sort-list
C++ || Insertion Sort || An Easy and Clear Way to Sort ✔
c-insertion-sort-an-easy-and-clear-way-t-g0ew
class Solution {\npublic:\n ListNode insertionSortList(ListNode head) {\n \n if(head == nullptr) return nullptr;\n \n int temp =
mahesh_1729
NORMAL
2022-10-08T13:59:33.819611+00:00
2022-10-08T13:59:33.819645+00:00
1,028
false
class Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n \n if(head == nullptr) return nullptr;\n \n int temp = 0;\n for(ListNode* curr = head; curr != nullptr; curr = curr->next){\n for(ListNode* prev = head; prev != curr; prev = prev->next){\n ...
3
0
['Linked List', 'C']
2
insertion-sort-list
c++ | | 2 approches | | clear solution
c-2-approches-clear-solution-by-dhirajmi-p0g1
1st approch\nclass Solution {\npublic:\n\n ListNode insertionSortList(ListNode head) {\n ListNode nxt = head -> next;\n while(nxt != NULL)\n {\n
DhirajMishra_
NORMAL
2022-09-08T05:44:02.166293+00:00
2022-09-08T06:54:37.970810+00:00
474
false
1st approch\nclass Solution {\npublic:\n\n ListNode* insertionSortList(ListNode* head) {\n ListNode *nxt = head -> next;\n while(nxt != NULL)\n {\n ListNode *curr = head;\n while(curr != nxt)\n {\n if(nxt -> val < curr -> val)\n swap(curr , nxt );\n ...
3
0
['Linked List', 'C']
1
insertion-sort-list
easy python solution with 69% TC
easy-python-solution-with-69-tc-by-nitan-coy5
\ndef insertionSortList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n\tdef add(node):\n\t\tcurr = self.ans\n\t\twhile(curr):\n\t\t\tif(curr.val < nod
nitanshritulon
NORMAL
2022-09-07T05:35:09.585560+00:00
2022-09-07T05:35:09.585636+00:00
1,940
false
```\ndef insertionSortList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n\tdef add(node):\n\t\tcurr = self.ans\n\t\twhile(curr):\n\t\t\tif(curr.val < node.val):\n\t\t\t\tprev = curr\n\t\t\t\tcurr = curr.next\n\t\t\telse: break\n\t\tnode.next, prev.next = prev.next, node\n\tself.ans = ListNode(-5001)\n\twhile(...
3
0
['Linked List', 'Python', 'Python3']
0
insertion-sort-list
Insertion Sort List | Java | Easy and Simple Solution
insertion-sort-list-java-easy-and-simple-i2oh
\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val)
Paridhicodes
NORMAL
2022-06-27T17:12:44.657853+00:00
2022-06-27T17:12:44.657900+00:00
581
false
```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode inserti...
3
0
['Java']
0
insertion-sort-list
Easy C++ Solution 5 lines
easy-c-solution-5-lines-by-tejesh07-quqj
I hope this solution helps you\n\nMostly in tech interviews interviewer may ask us not to use in-built functions. At that time this code might not be handy\n**\
tejesh07
NORMAL
2022-06-19T12:17:55.222017+00:00
2022-06-19T12:17:55.222058+00:00
412
false
# **I hope this solution helps you*\n\n***Mostly in tech interviews interviewer may ask us not to use in-built functions. At that time this code might not be handy***\n```**\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nul...
3
0
['Linked List', 'C']
0
insertion-sort-list
Java || Easy || Dummy
java-easy-dummy-by-amartya135-rwni
Please Upvote if you understood this (\uFF5E\uFFE3\u25BD\uFFE3)\uFF5E\n\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n ListN
amartya135
NORMAL
2022-04-01T14:48:16.630741+00:00
2022-04-01T14:48:16.630778+00:00
270
false
## **Please Upvote if you understood this** (\uFF5E\uFFE3\u25BD\uFFE3)\uFF5E\n```\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode curr = head;\n ListNode dummy = new ListNode(0);\n ListNode prev = dummy;\n ListNode nex = curr.next;\n \n whil...
3
1
['Java']
0
insertion-sort-list
Java Code
java-code-by-rizon__kumar-gjof
\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode start = new ListNode();\n start.next = head;\n ListNo
rizon__kumar
NORMAL
2021-12-31T06:02:12.538580+00:00
2021-12-31T06:02:12.538643+00:00
133
false
```\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode start = new ListNode();\n start.next = head;\n ListNode curr = head, prev = start;\n while(curr != null){\n if(curr.next != null &&(curr.next.val < curr.val)){\n // Insertion\n ...
3
0
[]
0
insertion-sort-list
Python | Simple Solution With Explanation
python-simple-solution-with-explanation-ihsue
\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\ncl
akash3anup
NORMAL
2021-12-15T11:40:58.912298+00:00
2022-03-11T07:31:37.385490+00:00
260
false
```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def insertionSortList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n currentNode = head\n previousNode = None\n ...
3
1
['Linked List', 'Python']
0
insertion-sort-list
[c++] solution O(1) space
c-solution-o1-space-by-giang_it-dyb4
The idea is to create a dummy node that would be the head of the sorted part of the list. Iterate over the given list and one by one add nodes to the sorted lis
giang_it
NORMAL
2021-12-15T02:14:39.985026+00:00
2021-12-15T02:35:50.785514+00:00
559
false
##### The idea is to create a dummy node that would be the head of the sorted part of the list. Iterate over the given list and one by one add nodes to the sorted list in the appropriate place following the insertion sort algorithm.\n\n\t/**\n\t * Definition for singly-linked list.\n\t * struct ListNode {\n\t * int...
3
1
['C']
1
insertion-sort-list
C/C++ Compatible Indirect Pointer solution with O(1) space | 0ms (100%)
cc-compatible-indirect-pointer-solution-aqhh2
<--------------\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F PLEASE UPVOTE \u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F----------
leoslf
NORMAL
2021-12-10T08:49:39.130249+00:00
2023-11-01T06:50:44.952423+00:00
247
false
<--------------\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F PLEASE UPVOTE \u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F\u2B06\uFE0F--------------->\n\nUsing an indirect pointer to the run (where we tried to maintain the sorted partition up to) and perform sorted insert between `head` and `*run`.\n\nD...
3
0
['C++']
0
insertion-sort-list
Java Easy Solution
java-easy-solution-by-thinagaran-0802
\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n \n ListNode temp = head;\n int n=0;\n while(temp!=null)
Thinagaran
NORMAL
2021-11-12T13:36:04.503353+00:00
2021-11-12T13:36:04.503384+00:00
407
false
\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n \n ListNode temp = head;\n int n=0;\n while(temp!=null)\n {\n n++;\n temp=temp.next;\n }\n temp=head;\n \n int arr[] = new int[n];\n int i=0;\n ...
3
5
['Array', 'Java']
1
insertion-sort-list
C++ Solution || 16ms O(1) space
c-solution-16ms-o1-space-by-thanos_ashu-chc2
\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n *
thanos_ashu
NORMAL
2021-10-28T13:28:25.493064+00:00
2021-10-28T13:28:25.493103+00:00
137
false
```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n List...
3
0
[]
0
insertion-sort-list
FASTER than 96.02%, C++, Clean Code
faster-than-9602-c-clean-code-by-aditiba-hyxq
Insertion Sort for Linked list.\n->Create a dummy node at the start of the linked list\n->Traverse the list start till end and for each node insert it at the ri
aditibahl
NORMAL
2021-07-04T12:02:02.577352+00:00
2021-07-04T12:25:12.950103+00:00
379
false
Insertion Sort for Linked list.\n->Create a dummy node at the start of the linked list\n->Traverse the list start till end and for each node insert it at the right position by using temporary node prev that tells us the right position for the node.\n->Return the next node of dummy as that will be the starting of linked...
3
0
['C']
0
insertion-sort-list
PYTHON SOL WITH LINE BY LINE EXPLANATION
python-sol-with-line-by-line-explanation-96dp
I have already added the required comments and explanation and if you still have any doubts comment down\n\n \n \n """\n We will cre
shubhamverma2604
NORMAL
2021-03-29T07:30:35.570179+00:00
2021-03-29T07:31:04.889931+00:00
342
false
I have already added the required comments and explanation and if you still have any doubts comment down\n\n \n \n """\n We will create a sorted linked list based on the given linkedlist by taking one val at a time and\n iterating and checking with prev and next pointer \n \n ...
3
0
['Linked List', 'Two Pointers', 'Python', 'Python3']
0
insertion-sort-list
Java Solution With Detailed Explaination
java-solution-with-detailed-explaination-nhmv
Explaination\n\n\t\thead : 1 -> 2 -> 4 -> 3 ->null\n\t\t\n\t\tdummyHead : (0)-> 1 -> 2 -> 4 ->3 -> null\n\t\t\n\t\t1 -> 2 -> 4 -> 3 -> null\n\t\t\t | |\n\t\t
credit_card
NORMAL
2020-10-13T11:46:40.198468+00:00
2020-10-13T11:48:41.863044+00:00
146
false
**Explaination**\n```\n\t\thead : 1 -> 2 -> 4 -> 3 ->null\n\t\t\n\t\tdummyHead : (0)-> 1 -> 2 -> 4 ->3 -> null\n\t\t\n\t\t1 -> 2 -> 4 -> 3 -> null\n\t\t\t | |\n\t\t head (head.val <= head.next.val) => continue\n\t\t \n\t\t\t\t\t head\n\t\t\t\t\t \t |\n\t\t(0) -> 1 -> 2 -> 4 -> 3 -> null\n\t\t\t\t | ...
3
0
['Java']
0
insertion-sort-list
[JavaScript] Clear and Easy to understand with ES6
javascript-clear-and-easy-to-understand-rf2lw
\nvar insertionSortList = function(head) {\n let newHead = new ListNode(0)\n while(head){\n const t = head\n head = head.next\n let c
kaiyiwing
NORMAL
2020-07-25T02:10:17.324588+00:00
2020-07-25T02:12:08.557621+00:00
635
false
```\nvar insertionSortList = function(head) {\n let newHead = new ListNode(0)\n while(head){\n const t = head\n head = head.next\n let cur = newHead\n while(cur){\n if(!cur.next || t.val <= cur.next.val){\n [cur.next, t.next] = [t, cur.next]\n b...
3
0
['JavaScript']
1
insertion-sort-list
C++ Easy Solution in O(1) space.
c-easy-solution-in-o1-space-by-manakupad-sghv
\nListNode* insertionSortList(ListNode* head) {\n // if list is empty or has only one node\n if(head == NULL || head->next == NULL)\n r
manakupadhyay
NORMAL
2020-06-15T20:07:01.860776+00:00
2020-06-15T20:07:01.860823+00:00
212
false
```\nListNode* insertionSortList(ListNode* head) {\n // if list is empty or has only one node\n if(head == NULL || head->next == NULL)\n return head;\n\t\t\t\n // make an empty list, it will store nodes in sorted order\n ListNode* newList = NULL;\n \n ListNode* current =...
3
0
[]
0