Remove Duplicates from Sorted Array

  • 0

    I have been trying to solve this question .

    I have implemented a solution in Python which I think is right however I still cannot pass the test cases.

    class Solution(object):
        def removeDuplicates(self, nums):
            :type nums: List[int]
            :rtype: int
            h_map = {}
            for i, v in enumerate(nums):
                if h_map.get(v, None):
                    h_map[v] = h_map[v] + 1
                    h_map[v] = 1
            nums = h_map.keys()
            return len(nums)

    Can we not use a dictionary to do this question? Can anyone point out whats wrong with this solution or approach.

Log in to reply

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