MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / sortList

Method sortList

java/0148-sort-list.java:43–58  ·  view source on GitHub ↗
(ListNode head)

Source from the content-addressed store, hash-verified

41 return dummy.next;
42 }
43 public ListNode sortList(ListNode head) {
44 if(head == null || head.next == null){
45 return head;
46 }
47
48 // Split the list in 2 halfs
49 ListNode left = head;
50 ListNode right = getMid(head);
51 ListNode tmp = right.next;
52 right.next = null;
53 right = tmp;
54
55 left = sortList(left);
56 right = sortList(right);
57 return merge(left, right);
58 }
59}
60
61// Using a Heap to sort the list

Callers

nothing calls this directly

Calls 4

getMidMethod · 0.95
mergeMethod · 0.95
addMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected