Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1190 from voski/0038-subsets
Browse files Browse the repository at this point in the history
0078 Subsets in Ruby
  • Loading branch information
dissesmac authored Sep 29, 2022
2 parents cc9426f + 5045428 commit 771a242
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ruby/78-Subsets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# @param {Integer[]} nums
# @return {Integer[][]}
def subsets(nums)
ans = []

recurse(nums, ans, [], 0)

ans
end


def recurse(nums, ans, curr, i)
if i == nums.length
ans << curr.clone
return
end


curr << nums[i]
recurse(nums, ans, curr, i + 1)

curr.pop
recurse(nums, ans, curr, i + 1)
end

0 comments on commit 771a242

Please sign in to comment.