1. 문제
2. 나의 풀이
class ListNode(object):
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution(object):
def removeElements(self, head, val):
"""
:type head: ListNode
:type val: int
:rtype: ListNode
"""
prev_node = None
current_node = head
while current_node:
if prev_node and current_node.val == val:
prev_node.next = current_node.next
if not prev_node and current_node.val == val:
head = current_node.next
if current_node.val != val:
prev_node = current_node
current_node = current_node.next
return head
3. 남의 풀이