parent
6afccb6b4d
commit
7c6930971d
|
|
@ -245,13 +245,15 @@ Python:
|
|||
# def __init__(self, val=0, next=None):
|
||||
# self.val = val
|
||||
# self.next = next
|
||||
|
||||
class Solution:
|
||||
def removeElements(self, head: ListNode, val: int) -> ListNode:
|
||||
dummy_head = ListNode(next=head) #添加一个虚拟节点
|
||||
dummy_head = ListNode(next=head)
|
||||
cur = dummy_head
|
||||
while(cur.next!=None):
|
||||
if(cur.next.val == val):
|
||||
cur.next = cur.next.next #删除cur.next节点
|
||||
|
||||
while cur.next:
|
||||
if cur.next.val == val:
|
||||
cur.next = cur.next.next # 删除下一个节点
|
||||
else:
|
||||
cur = cur.next
|
||||
return dummy_head.next
|
||||
|
|
|
|||
Loading…
Reference in New Issue