IT_World

[leetcode] 83. Remove Duplicates from Sorted List 본문

Coding test/programmers - single

[leetcode] 83. Remove Duplicates from Sorted List

engine 2022. 4. 3. 23:58
class Solution:
    def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
        dta = ListNode(0)
        dta.next = head
        
        dataset = set()
        
        while head and head.next:
            dataset.add(head.val)
            
            while head.next and head.next.val in dataset :
                head.next = head.next.next
                
                head = head.next
                
            return dta.next
Comments