(self, head: ListNode, val: int)
| 1 | class Solution: |
| 2 | def removeElements(self, head: ListNode, val: int) -> ListNode: |
| 3 | dummy = ListNode(next=head) |
| 4 | prev, curr = dummy, head |
| 5 | |
| 6 | while curr: |
| 7 | nxt = curr.next |
| 8 | |
| 9 | if curr.val == val: |
| 10 | prev.next = nxt |
| 11 | else: |
| 12 | prev = curr |
| 13 | |
| 14 | curr = nxt |
| 15 | return dummy.next |