init: hot100 algo project with .gitignore
This commit is contained in:
15
01-two-sum/solution.py
Normal file
15
01-two-sum/solution.py
Normal file
@@ -0,0 +1,15 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user