O(n) java iterative solution


  • 0
    A

    public class Solution {

    public ListNode deleteDuplicates(ListNode head) {
        if(head == null){
            return head;
        }
        ListNode start = head;
        ListNode temp = head.next;
        while(temp != null){
            if(temp.val == start.val){
                start.next = temp.next;
            }
            else{
                start = temp;
            }
            temp = start.next;
        }
        return head;
    }
    

    }


Log in to reply
 

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