Grokking Data Structures & Algorithms for Coding Interviews
Vote

0% completed

​

Sort List (medium)

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 3 years ago

public ListNode sortList(ListNode head) { if(head==null){ return head; } ListNode current = head; ListNode next = head.next; while(next != null){ if(next.val <= current.val){ int temp = next.val; next.val = current.val; current.val = temp; } if(next.next== null){ current = current.next; next = current.next; }else{ next = next.next; } } return head; }

Reading Progress

0%


Vote for new content