My Not so short Java code beats 96.63%. Easy to understand as well. It can't get better than this I suppose.

  • 2

    There are slight modifications which you can do but that will only make code more complex and hard to understand. In the Interview if you write this kind of easy-to-get-along code, your Interviewer might get happy.

    public ListNode insertionSortList(ListNode head) { //Pretty efficient.
    		if (head == null || == null)
    			return head;
    		ListNode curr = head;
    		ListNode dummy = new ListNode(0); = head;
    		ListNode first = dummy;
    		while ( != null) {
    			if (curr.val > { // All messy stuff but make complete sense if you can think.
    				while ( < 
    					first =;
    				ListNode node =; // Some house keeping stuff here. =; =; = node;
    				first = dummy;
    			} else
    				curr =;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.