链表_leetcode203

# 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
posted @ 2019-03-19 10:59  AceKo  阅读(116)  评论(0编辑  收藏  举报