Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
What is wrong with mutating the data - that seems to be O(n) runtime and constant space complexity - is it consider valid solution?

Syed Ahmed

Jan 22, 2024

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; }

0

0

Comments
Comments

On this page