We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 722cc13 commit 93a8f22Copy full SHA for 93a8f22
Insertion Sort List.py
@@ -1,6 +1,14 @@
1
class Solution:
2
+ def isListAllSorted(self, head):
3
+ current = head
4
+ while current and current.next:
5
+ if current.val > current.next.val:
6
+ return False
7
+ current = current.next
8
+ return True
9
+
10
def insertionSortList(self, head):
- if head == None:
11
+ if head == None or self.isListAllSorted(head):
12
return head
13
dummy = ListNode(-9223372036854775808)
14
dummy.next = head
0 commit comments