23 lines
728 B
Python
23 lines
728 B
Python
def twoSum(nums, target):
|
|
"""
|
|
:type nums: List[int]
|
|
:type target: int
|
|
:rtype: List[int]
|
|
"""
|
|
for i in range(len(nums)):
|
|
for j in range(i+1, len(nums)):
|
|
if nums[i] + nums[j] == target:
|
|
#print(f'i is {nums[i]}, j is {nums[j]}')
|
|
return [i,j]
|
|
|
|
#hashmap = {}
|
|
|
|
#for i in range(len(nums)):
|
|
#complacement = target - nums[i]
|
|
#if complacement in hashmap:
|
|
# return [i, hashmap[complacement]]
|
|
# else:
|
|
#hashmap[nums[i]] = i
|
|
|
|
print(twoSum([2,7,11,15], 9))
|
|
print(twoSum([3,2,4], 6)) |