Python - Why my solution using Counter doesn't work?

  • 0

    Hi all, could you let me know why my O(n) solution with Counter in Python doesn't work with this test case? I tried this in my local IDEA and it passed with the same test case. Thanks.

    from collections import Counter
    class Solution(object):
        def removeDuplicates(self, nums):
            return len([i for i in Counter(nums)])

    Input: [1,1,2]
    Output: [1,1]
    Expected: [1,2]

  • 0

    Because you didn't change nums.
    The removal needs to be in-place.

Log in to reply

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