mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
fix 0203.移除链表元素.md
修复某个变量编译时的类型问题。
This commit is contained in:
@ -385,7 +385,8 @@ function removeElements(head: ListNode | null, val: number): ListNode | null {
|
||||
if (cur.val === val) {
|
||||
pre.next = cur.next;
|
||||
} else {
|
||||
pre = pre.next;
|
||||
//此处不加类型断言时:编译器会认为pre类型为ListNode, pre.next类型为ListNode | null
|
||||
pre = pre.next as ListNode;
|
||||
}
|
||||
cur = cur.next;
|
||||
}
|
||||
|
Reference in New Issue
Block a user