[leetcode203]Remove Linked List Elements

xiaoxiao2021-02-28  87

# 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         """         dummy=cur=ListNode(0)         dummy.next=head         while cur and cur.next:             if cur.next.val==val:                 cur.next=cur.next.next             else:                 cur=cur.next

        return dummy.next

学习视频https://www.youtube.com/watch?v=l3fNiN1Fz9E

转载请注明原文地址: https://www.6miu.com/read-60769.html

最新回复(0)