Why this python solution cannot handle [1,1] case?


  • 0
    Z
    class Solution(object):
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        s=set()
        if not head:
            return None
        else:
            if not head.next:
                return head
            else:
                cur1,cur2=head,head
                s.add(head.val)
                while cur1.next:
                    cur1=cur1.next
                    if cur1.val not in s:
                        cur2.next=cur1
                        cur2=cur2.next
                        s.add(cur1.val)
                return head
    

    I don't know why this python solution gets error in the case of [1,1] as input? I'm a new beginner
    When I test it on my eclipse, it also works correctly.
    Any one can help me? Thank you in advance.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.