Update 0203.移除链表元素.md

The variable cur could be null, should add the union to the type of cur.
This commit is contained in:
Aaron-Lin-74
2022-03-04 10:52:42 +11:00
committed by GitHub
parent fdedb546b3
commit cc302a9e8d

View File

@ -324,7 +324,7 @@ function removeElements(head: ListNode | null, val: number): ListNode | null {
head = head.next;
}
if (head === null) return head;
let pre: ListNode = head, cur: ListNode = head.next;
let pre: ListNode = head, cur: ListNode | null = head.next;
// 删除非头部节点
while (cur) {
if (cur.val === val) {