16 lines
386 B
Python
16 lines
386 B
Python
from typing import List
|
|
|
|
class Solution:
|
|
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
|
hash = {}
|
|
for i, num in enumerate(nums):
|
|
another = target - num
|
|
if another in hash:
|
|
return [hash[another], i]
|
|
hash[num] = i
|
|
|
|
|
|
if __name__ == "__main__":
|
|
res = Solution().twoSum([2,7,11,15], 9)
|
|
print(res)
|