# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def removeElements(self, head, val):
"""
:type head: ListNode
:type val: int
:rtype: ListNode
"""
dummyHead = ListNode(0)
dummyHead.next = head
pre = dummyHead
while pre.next:
if pre.next.val == val :
delNode = pre.next
pre.next = delNode.next
else:
pre = pre.next
return dummyHead.next