Two Sum
- Two Sum (build hash of elem, idx then look up hash)
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
delta = {}
for i in range(len(nums)):
delta[target - nums[i]] = i
# print(delta)
for i in range(len(nums)):
if nums[i] in delta:
# Don't report duplicate indices
if i != delta[nums[i]]:
return [i, delta[nums[i]]