Python Code O(n)


  • 0
    W
    class Solution(object):
        def twoSum(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            table = {}
    
            for k, v in enumerate(nums):
              if target-v in table :
                  return [k, table[target-v]]
              else:
                  table[v] = k    
    

Log in to reply
 

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