mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
20 lines
359 B
Python
20 lines
359 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
def remove_elements(head, val):
|
|
|
|
sentinel = Node(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
|
|
|