Remove Duplicates from Sorted Array


  • 0
    M

    I have been trying to solve this question .
    https://leetcode.com/problems/remove-duplicates-from-sorted-array/#/description

    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
                else:
                    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.