Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions two_sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Given the list of numbers and a target, We have to find two numbers such that the addition of two numbers in the list should be equal to the target.
#Input: list of numbers, target
#Output: Index of two numbers
class Solution:
def twoSum(self, nums, target):
hash={}
for i in range(len(nums)):
com = target - nums[i]
if com not in hash:
hash[nums[i]]=i
else:
return [hash[com],i]

s1 = Solution()
nums = [2,7,11,15]
target = 9
print(s1.twoSum(nums , target ))