Java: Linear Time O(n) ,Recursion


  • 0
    X

    public class Solution {
    public int checker;
    public ListNode deleteDuplicates(ListNode head) {
    if(head == null || head.next == null){
    if(head != null) checker = head.val;
    return head;
    }
    head.next = deleteDuplicates(head.next);
    if(head.val == checker){
    if(head.next != null && head.next.val == checker) return head.next.next;
    else return head.next;
    }
    checker = head.val;
    return head;
    }
    }


Log in to reply
 

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