My recursive solution java


  • 0
    L

    public ListNode deleteDuplicates(ListNode head) {

        if(head == null || head.next == null){
            return head;
        }
        
        if(head.val == head.next.val){
            head.next = head.next.next;
            deleteDuplicates(head);
        }else{
            deleteDuplicates(head.next);
        }
        return head;
    }

Log in to reply
 

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