Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Topic1_Arrays/Day2207/TranVanThi/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# two sum

def hashMap(nums, target):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the way you think to get the solution.
Add the time and space complexity

numMap = dict()
for i in range(len(nums)):
flag = target - nums[i]
if flag in numMap:
return [numMap[flag], i]
numMap[nums[i]] = i

return []


if __name__ == "__main__":
nums = [2,7,11,15]
target = 9
n = len(nums)
hashMap(nums=nums, target=target)