First time: My Java code Runtime: 68 ms


  • 0
    W
    public ListNode DeleteDuplicates(ListNode head) {
    	if (head == null || head.next == null)
    		return head;
    	
    	ListNode pos = head;
    	ListNode posnext = head.next;
    	while ( posnext != null ) {
    		if (posnext.val == pos.val){
    			pos.next = posnext.next;
    		}else{
    			pos=posnext;
    		}
    		posnext=pos.next;
    	}
    	return head;
    }

  • 0

    I think you put the code in the wrong section for another problem, this doesn't seem to be the code for "Remove Duplicates from Sorted Array"


Log in to reply
 

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