We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 309cb69 commit 4b16780Copy full SHA for 4b16780
0001/two_sum.py
@@ -0,0 +1,18 @@
1
+class Solution(object):
2
+ def twoSum(self, nums, target):
3
+ """
4
+ :type nums: List[int]
5
+ :type target: int
6
+ :rtype: List[int]
7
8
+ hash_table = dict()
9
+
10
+ # Iterating the list
11
+ for i, num in enumerate(nums):
12
13
+ # If the target-num in dict then, we found the solution
14
+ try:
15
+ hash_table[target - num]
16
+ return [hash_table[target - num], i]
17
+ except KeyError:
18
+ hash_table[num] = i
0 commit comments