mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update 0203.移除链表元素.md
The variable cur could be null, should add the union to the type of cur.
This commit is contained in:
@ -324,7 +324,7 @@ function removeElements(head: ListNode | null, val: number): ListNode | null {
|
|||||||
head = head.next;
|
head = head.next;
|
||||||
}
|
}
|
||||||
if (head === null) return head;
|
if (head === null) return head;
|
||||||
let pre: ListNode = head, cur: ListNode = head.next;
|
let pre: ListNode = head, cur: ListNode | null = head.next;
|
||||||
// 删除非头部节点
|
// 删除非头部节点
|
||||||
while (cur) {
|
while (cur) {
|
||||||
if (cur.val === val) {
|
if (cur.val === val) {
|
||||||
|
Reference in New Issue
Block a user