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

Method merge

java/0148-sort-list.java:21–42  ·  view source on GitHub ↗
(ListNode left, ListNode right)

Source from the content-addressed store, hash-verified

19 return slow;
20 }
21 public ListNode merge(ListNode left, ListNode right){
22 ListNode dummy = new ListNode();
23 ListNode tail = dummy;
24
25 while(left != null && right != null){
26 if(left.val < right.val){
27 tail.next = left;
28 left = left.next;
29 }else{
30 tail.next = right;
31 right = right.next;
32 }
33 tail = tail.next;
34 }
35 if(left != null){
36 tail.next = left;
37 }
38 if(right != null){
39 tail.next = right;
40 }
41 return dummy.next;
42 }
43 public ListNode sortList(ListNode head) {
44 if(head == null || head.next == null){
45 return head;

Callers 2

sortListMethod · 0.95
topKFrequentMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected