Python O(n) one pass solution


  • 0
    Y
    def twoSum(self, nums, target):
            map = {}
        
            for i, v in enumerate(nums):
                if target - v in map and i != map[target - v]:
                    return [i, map[target - v]]
                map[v] = i
                
            raise Exception('no answer')

Log in to reply
 

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