1ms java solution


  • 1
    S
    public ListNode deleteDuplicates(ListNode head) {
            if(head == null) return null;
            if(head.next==null) return head;
            ListNode r = head;
            ListNode root = head;
            while(head!=null){
                if(head.next!=null && head.val == head.next.val){
                    root = head;
                    while(root.next!=null && root.val==root.next.val) root = root.next;
                    head.next = root.next;
                }
                head = head.next;
            }
            return r;
        }

Log in to reply
 

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