Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2022 from saip7795/sp/combination-sum
Browse files Browse the repository at this point in the history
Create : 0039-Combination-Sum.rb
  • Loading branch information
saip7795 authored Jan 17, 2023
2 parents 3c6fac4 + 67c47ed commit 3ea0fd8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ruby/0039-combination-sum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def combination_sum(candidates, target)
@result = []
@target = target
@candidates = candidates
def dfs(i, current, total)
if total == @target
@result.append(current.dup())
return
end
if i >= @candidates.length() || total > @target
return
end

current.append(@candidates[i])
dfs(i, current, total+@candidates[i])
current.pop()
dfs(i+1, current, total)
end

dfs(0,[],0)
return @result
end

0 comments on commit 3ea0fd8

Please sign in to comment.