We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 11f480c + 75c3be0 commit b858d6cCopy full SHA for b858d6c
solution/001.Two Sum/Solution2.py
@@ -0,0 +1,10 @@
1
+#time 32ms
2
+class Solution(object):
3
+ def twoSum(self, nums, target):
4
+ buff = {}
5
+ for i in range(len(nums)):
6
+ if nums[i] in buff: #如果这个数在字典里,证明之前有数可以和他匹配
7
+ return buff[nums[i]],i #返回之前留信息的数的编号,和当前这个数的编号
8
+ else:
9
+ buff[target - nums[i]] = i #这个数字不在字典里,那么就存一下他需要匹配的数,并记录编号
10
+
0 commit comments