My simple java solution


  • 0
    C
       public class Solution {
       public ListNode deleteDuplicates(ListNode head) {
        
    	ListNode previous = head;
    	ListNode latter = new ListNode(0);
    	
    	if(head == null)
    		return head;
        
    	//ListNode latter = head.next;
    	while((previous != null)&&(previous.next != null))
    	{
    		latter=previous.next;
    		if(previous.val == latter.val)
    		{
    			previous.next=latter.next;
    			//latter.next=null;
    		}
    		else
    		{
    			previous=latter;
    		}
    	}
    	return head;
    }
    

    }


  • 0
    D
    latter.next=null;
    

    do nothing


  • 0
    C

    you are right,
    This step is redundant.~~~


Log in to reply
 

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