My Java solution...


  • 0
    public ListNode deleteDuplicates(ListNode head) {
        
        if(head == null || head.next == null)
            return head;
        
        ListNode v = new ListNode(0);
        v.next = head;
        ListNode curr = v;
        
        while(curr.next != null){
            if(curr.next.next != null && curr.next.val == curr.next.next.val){
                int val = curr.next.val;
                while(curr.next != null && curr.next.val == val)
                    curr.next = curr.next.next;
            } else
                curr = curr.next;
        }
        return v.next;
    }

Log in to reply
 

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