Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 740 Bytes

83.md

File metadata and controls

42 lines (31 loc) · 740 Bytes

Remove Duplicates from Sorted List

Description

link


Solution

See Code

注意边界问题


Code

O(n)

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        pre = cur = res = head
        while cur and cur.next:
            while cur.next and cur.val == cur.next.val:
                cur = cur.next
            pre.next = cur.next
            pre = cur.next
            cur = cur.next
        return res