Share my code in Java


  • -1
    W
    public class Solution {
        public ListNode insertionSortList(ListNode head) {
        		ListNode ptr = head;
        		ListNode ptr2;
        		int buf = 0;
        		while(ptr != null){
        			ptr2 = head;
        			while(ptr2!=ptr){
        				if(ptr2.val>ptr.val){
        	    				buf=ptr.val;
        	    				ptr.val=ptr2.val;
        	    				ptr2.val=buf;
        				}
        				ptr2=ptr2.next;
        			}
        			ptr=ptr.next;
        		}
        		return head;
        }
    }

  • 0
    N

    ok.ok.You just change the value.


Log in to reply
 

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