From a2607c2b72e5e0f2b81690b7722503f20272e689 Mon Sep 17 00:00:00 2001 From: saip7795 Date: Fri, 13 Jan 2023 13:59:08 -0500 Subject: [PATCH 1/2] Ruby Solution for Combination Sum --- ruby/0039-combinatiion-sum.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ruby/0039-combinatiion-sum.rb diff --git a/ruby/0039-combinatiion-sum.rb b/ruby/0039-combinatiion-sum.rb new file mode 100644 index 000000000..0a387b3a3 --- /dev/null +++ b/ruby/0039-combinatiion-sum.rb @@ -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 \ No newline at end of file From 67c47ed2c67b68d59001709d70cf486395bcc974 Mon Sep 17 00:00:00 2001 From: saip7795 Date: Fri, 13 Jan 2023 14:02:21 -0500 Subject: [PATCH 2/2] Fix the typo in file name --- ruby/{0039-combinatiion-sum.rb => 0039-combination-sum.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ruby/{0039-combinatiion-sum.rb => 0039-combination-sum.rb} (100%) diff --git a/ruby/0039-combinatiion-sum.rb b/ruby/0039-combination-sum.rb similarity index 100% rename from ruby/0039-combinatiion-sum.rb rename to ruby/0039-combination-sum.rb