Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 702 Bytes

mian-shi-ti-02.01.-yi-chu-zhong-fu-jie-dian.md

File metadata and controls

33 lines (25 loc) · 702 Bytes

面试题 02.01. 移除重复节点

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

class Solution:
    def removeDuplicateNodes(self, head: ListNode) -> ListNode:
        dit = {}
        dummy = ListNode(-1)
        dummy.next = head
        pre = dummy
        while head:
            if head.val not in dit:
                pre.next = head
                dit[head.val] = 1
                head = head.next
                pre = pre.next
                
            else:
                head = head.next
            # print(dit)
        pre.next = None
        return dummy.next