leetcode82Remove Duplicates from Sorted List II

xiaoxiao2021-02-28  98

# Definition for singly-linked list. # class ListNode(object): #     def __init__(self, x): #         self.val = x #         self.next = None class Solution(object):     def deleteDuplicates(self, head):         """         :type head: ListNode         :rtype: ListNode         """         dummy=cur=ListNode(0)         dummy.next=head         while head and head.next:             if head.val==head.next.val:                 while head and head.next and head.val==head.next.val:                     head=head.next                 head=head.next                 cur.next=head             else:                 cur.next=head                 cur=cur.next                 head=head.next         return dummy.next
转载请注明原文地址: https://www.6miu.com/read-41220.html

最新回复(0)