Skip to content

Commit

Permalink
Merge pull request youngyangyang04#1138 from Aaron-Lin-74/patch-2
Browse files Browse the repository at this point in the history
Update 0203.移除链表元素.md
  • Loading branch information
youngyangyang04 authored Mar 23, 2022
2 parents 5a7ab02 + 09c1bd8 commit 9139ffb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions problems/0203.移除链表元素.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,14 @@ function removeElements(head: ListNode | null, val: number): ListNode | null {

```typescript
function removeElements(head: ListNode | null, val: number): ListNode | null {
head = new ListNode(0, head);
let pre: ListNode = head, cur: ListNode = head.next;
let dummyHead = new ListNode(0, head);
let pre: ListNode = dummyHead, cur: ListNode | null = dummyHead.next;
// 删除非头部节点
while (cur) {
if (cur.val === val) {
pre.next = cur.next;
} else {
pre = pre.next;
pre = cur;
}
cur = cur.next;
}
Expand Down

0 comments on commit 9139ffb

Please sign in to comment.