赞
踩
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNode]: if head==None: return dummy_head=ListNode(next=head) cur=dummy_head while cur.next: if cur.next.val==val: cur.next=cur.next.next else: cur=cur.next return dummy_head.next
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。