class Solution(object):
def removeElements(self, head, val):
"""
:type head: ListNode
:type val: int
:rtype: ListNode
"""
if not head:
return head
res=ListNode(0)
res.next=head
p=head
q=res
while p:
while p and p.val == val:
p=p.next
q.next=p
q=p
if p:
p=p.next
return res.next
python leetcode 203. Remove Linked List Elements
最新推荐文章于 2024-07-23 14:36:35 发布