We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 9d29d38 + 65b92e8 commit f32b60eCopy full SHA for f32b60e
0001/README.md
@@ -0,0 +1,7 @@
1
+# Two sum
2
+
3
+### Problem statemen
4
+Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
5
+You may assume that each input would have exactly one solution, and you may not use the same element twice.
6
7
+You can return the answer in any order.
0001/two_sum.py
@@ -0,0 +1,18 @@
+class Solution(object):
+ def twoSum(self, nums, target):
+ """
+ :type nums: List[int]
+ :type target: int
+ :rtype: List[int]
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