class Solution(object):
def removeElements(self, head, val):
"""
:type head: ListNode
:type val: int
:rtype: ListNode
"""
prehead = ListNode(-1)
prehead.next = head
pre = prehead
while head:
if head.val == val:
pre.next = head.next
else:
pre = head
head = head.next
return prehead.next
原文:https://www.cnblogs.com/panweiwei/p/12857192.html