MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / removeElements

Method removeElements

python/0203-remove-linked-list-elements.py:2–15  ·  view source on GitHub ↗
(self, head: ListNode, val: int)

Source from the content-addressed store, hash-verified

1class 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

Callers

nothing calls this directly

Calls 1

ListNodeClass · 0.70

Tested by

no test coverage detected