1. Two Sum
Approach 1: Store value, index pairs
class Solution(object):
def twoSum(self, nums, target):
"""
https://leetcode.com/problems/two-sum/description/
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
di = {}
for i in range(len(nums)):
if target - nums[i] in di:
return [di[target - nums[i]], i]
else:
di[nums[i]] = iLast updated