Skip to content

Commit

Permalink
2020-01-25
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed Jan 25, 2020
1 parent 16f6617 commit 4df208c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions 0001.两数之和/0001-两数之和.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ def twoSum(self, nums, target):
:type target: int
:rtype: List[int]
"""
hashmap = {}
for i, x in enumerate(nums):
if hashmap.has_key(target - x):
return [hashmap[target - x], i]
else:
hashmap[x] = i

return []
dic = {}
for i, num in enumerate(nums):
if target - num in dic:
return [dic[target - num], i]
dic[num] = i

0 comments on commit 4df208c

Please sign in to comment.