Skip to content

083 remove duplicates from sorted list

83. Remove Duplicates from Sorted List

题目: https://leetcode.com/problems/remove-duplicates-from-sorted-list/

难度:

Easy

dummy 大法

class Solution(object):
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        dummy = head
        while head:
            while head.next and head.next.val == head.val:
                head.next = head.next.next    # skip duplicated node
            head = head.next     # not duplicate of current node, move to next node
        return dummy



回到顶部