Sunday, September 15, 2019

83. remove-duplicated-from-sorted

83. remove-duplicated-from-sorted
Runtime: 0 ms, faster than 100.00% of Java online submissions for Remove Duplicates from Sorted List.
Memory Usage: 36.2 MB, less than 100.00% of Java online submissions for Remove Duplicates from Sorted List.
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode mockHead = new ListNode(-1);
        mockHead.next = head;

        while(head != null && head.next != null){
            if(head.val == head.next.val){
                head.next = head.next.next;
                continue;
            }
            head = head.next;
        }

        return mockHead.next;
        
    }
}

No comments:

Post a Comment