Skip to content

Commit 4df208c

Browse files
committed
2020-01-25
1 parent 16f6617 commit 4df208c

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

0001.两数之和/0001-两数之和.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ def twoSum(self, nums, target):
55
:type target: int
66
:rtype: List[int]
77
"""
8-
hashmap = {}
9-
for i, x in enumerate(nums):
10-
if hashmap.has_key(target - x):
11-
return [hashmap[target - x], i]
12-
else:
13-
hashmap[x] = i
14-
15-
return []
8+
dic = {}
9+
for i, num in enumerate(nums):
10+
if target - num in dic:
11+
return [dic[target - num], i]
12+
dic[num] = i

0 commit comments

Comments
 (0)