Skip to content

Commit 93a8f22

Browse files
committed
make test cases pass for insertion sort list
1 parent 722cc13 commit 93a8f22

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Insertion Sort List.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
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+
210
def insertionSortList(self, head):
3-
if head == None:
11+
if head == None or self.isListAllSorted(head):
412
return head
513
dummy = ListNode(-9223372036854775808)
614
dummy.next = head

0 commit comments

Comments
 (0)