DAY 8
203.移除链表元素
用了创建虚拟头结点的方法,比较简单
class Solution:
def removeElements(self, head: ListNode, val: int) -> ListNode:
dummy_head = ListNode(next = head)
cur = dummy_head
while (cur.next != None):
if(cur.next.val == val):
cur.next = cur.next.next
else:
cur = cur.next
return dummy_head.next
emp1 = solution1()
head=[1,2,6,3,4,5,6]
val = 6
emp1.removeElements(head, val)
#输出:[1,2,3,4,5]