Remove Duplicates from Sorted List 2020-09-14 03:13

Problem Description

public static ListNode deleteDuplicates(ListNode head) {
    ListNode cursor = head;
    while (cursor!=null && cursor.next != null) {
        if (cursor.val == cursor.next.val) {
            cursor.next = cursor.next.next;
        } else {
            cursor = cursor.next;
        }
    }
    return head;
}
Runtime Memory
1 ms 41.8 MB

henryxi leetcode list

EOF