Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hurahhhh! #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions 1 - Two Sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ def twoSum(self, nums, target):
return [numsDict[target-i][0],numsDict[i][0]]
elif len(numsDict[target-i]) > 1:
return numsDict[target-i]

# simple & elegant
class Solution(object):
def twoSum(self, nums, target):
for i in range(len(nums)):
for j in range(i+1,len(nums)):
if nums[i]+nums[j]==target:
return [i,j]

11 changes: 11 additions & 0 deletions 90 - Subsets II.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ def subsetsWithDup(self, nums):
i += dupes
return pset

# Solution 3 - MB-44
class Solution(object):
def subsetsWithDup(self,nums):
subsets = [[]]
if len(nums) == 1:
subsets.append(nums[0])
else:
for i in range(len(nums)-1):
for j in range(i,len(nums)):
subsets.append(nums[i:j+1])
return subsets