Zheaoli / do-something-right

MIT License
37 stars 3 forks source link

2022-09-17 #363

Open Zheaoli opened 2 years ago

Zheaoli commented 2 years ago

2022-09-17

gongpeione commented 2 years ago
/*
 * @lc app=leetcode id=83 lang=typescript
 *
 * [83] Remove Duplicates from Sorted List
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

function deleteDuplicates(head: ListNode | null): ListNode | null {
    if (!head) {
        return null;
    }

    let pointer = head;
    while (pointer.next) {
        const next = pointer.next;
        if (pointer.val === next.val) {
            pointer.next = next.next;
        } else {
            pointer = next;
        }
    }

    return head;
};
// @lc code=end

微信id: 弘树 来自 vscode 插件