1ms Java solution


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

  • 0
    T

    Hmm this is actually O(n) worst case space complexity because of head argument and function call bookkeeping.


Log in to reply
 

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