Skip to content

Commit

Permalink
Ruby Solution for Subsets II
Browse files Browse the repository at this point in the history
  • Loading branch information
saip7795 committed Jan 18, 2023
1 parent ad87adb commit 9e33704
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ruby/0090-subsets-ii.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def subsets_with_dup(nums)
@result = []
@nums = nums.sort!

def backtrack(i,subset)
if i == @nums.length
@result.append(subset.dup())
return
end

subset.append(@nums[i])
backtrack(i+1,subset)
subset.pop()

while ((i+1 < @nums.length) && (@nums[i] == @nums[i+1]))
i +=1
end

backtrack(i+1,subset)
end

backtrack(0,[])

return @result
end

0 comments on commit 9e33704

Please sign in to comment.