Very easy to understand Python O(n)


  • 0
    S
    class Solution(object):
        def twoSum(self, nums, target):
            # assume exatcly one solution
            map={}
            for i, x in enumerate(nums):
                if x in map:
                    return [i, map[x]]
                else:
                    map[target-x]=i
    

Log in to reply
 

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