Why doesn't this Python solution work? (Passed all tests in Python Shell)

  • 0
    class Solution(object):
        def removeDuplicates(self, nums):
            unique = {}
            for i in nums:
                if i not in unique:
                    unique[i] = [i]
                    unique[i] += [i]
            result = []
            for i in unique:
                if len(unique[i]) > 2:
                    result += unique[i][0:2]
                    result += unique[i]
            nums = result
            return len(nums)

    Just wondering why this worked as a Python script but is failing the test case [1,1,1,2] on LeetCode? Any pointers would be really appreciated!

  • 0

    @christinayan my code is different from yours, but I failed same exact test. It passes the test locally.

Log in to reply

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