Super simple python solution


  • 0
    P
    def twoSum(self, nums, target):
        dict_nums = {}
        for i in range(len(nums)):
            if(nums[i] in dict_nums):
                return [i, dict_nums[nums[i]]]
            else:
                dict_nums[target - nums[i]] = i
    

    This is correct but it's kind of slowish? Is it because the new question forces you to return a list?


  • 1
    P

    dict is slow for large amont of number, it generation is lose time and space,though its quick for search.....


Log in to reply
 

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