Java Solution.Not sure why it takes 1 ms?


  • 0
    Z
    public ListNode deleteDuplicates(ListNode head) {
            
            if(head == null) return null;
            ListNode curr = head;
            
            while(curr!=null)
            {
                ListNode next = curr.next;
                while(next!=null && next.val==curr.val)
                {
                    next = next.next;       
                }
                curr.next = next;
                curr =  curr.next;
            }
            
            return head;
        }
    

Log in to reply
 

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