Clearly and simple java solution


  • 0
    N
    public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        
        if(head==null)
            return head;
        
        ListNode p = head;
        
        while(p.next!=null){
            
            if(p.next.val == p.val)
                p.next = p.next.next;
            else
                p = p.next;
        }
        
        return head;
    }
    

    }


  • 0
    S

    can you explain me the difference between return head and return p. Why does return p give a wrong ans


Log in to reply
 

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