Simple java solution


  • 0
    L
    public ListNode deleteDuplicates(ListNode head) {
        if(head==null || head.next==null) return head;
        ListNode p=head;
        ListNode nullHead=new ListNode(0);
        nullHead.next=head;
        ListNode front=nullHead;
        while(p.next!=null){
            if(p.val==p.next.val){
                front.next=p.next;
                p=p.next;
            }
            else{
                front=p;
                p=p.next;
            }
        }
        return nullHead.next;
    }

Log in to reply
 

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