My java solution


  • 0
    L
     public ListNode deleteDuplicates(ListNode head) {
        ListNode p = head;
        ListNode nullHead = new ListNode(-1);
        ListNode q = nullHead;
        boolean flag = false;
        while(p != null){
            flag = false;
            while(p.next != null && p.val == p.next.val){
                p = p.next;
                flag = true;
            }
            if(!flag){
                q.next = p;
                q = q.next;
            }
            p = p.next;
        }
        q.next = null;
        return nullHead.next;
    }

Log in to reply
 

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