mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Create remove_elements.py
This commit is contained in:
parent
fb7059d0e6
commit
2c1c7c0ff7
19
linked_lists/remove_elements.py
Normal file
19
linked_lists/remove_elements.py
Normal file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
def remove_elements(head, val):
|
||||
|
||||
sentinel = ListNode(0)
|
||||
sentinel.next = head
|
||||
prev, current = sentinel, head
|
||||
|
||||
while current:
|
||||
if current.val == val:
|
||||
prev.next = current.next
|
||||
else:
|
||||
prev = current
|
||||
current = current.next
|
||||
|
||||
return sentinel.next
|
||||
|
Loading…
x
Reference in New Issue
Block a user