Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 deletions 0001/two
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
for j in range(i + 1, len(nums)):

if nums[i] + nums[j] == target:

return [i,j]
else:
pass

29 changes: 11 additions & 18 deletions 0001/two_sum.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
hash_table = dict()

# Iterating the list
for i, num in enumerate(nums):

# If the target-num in dict then, we found the solution
try:
hash_table[target - num]
return [hash_table[target - num], i]
except KeyError:
hash_table[num] = i
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
for j in range(i + 1, len(nums)):

if nums[i] + nums[j] == target:

return [i,j]
else:
pass

11 changes: 11 additions & 0 deletions 0001/twosum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
for j in range(i + 1, len(nums)):

if nums[i] + nums[j] == target:

return [i,j]
else:
pass