Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3ea0fd8

Browse files
authored
Merge pull requestneetcode-gh#2022 from saip7795/sp/combination-sum
Create : 0039-Combination-Sum.rb
2 parents3c6fac4 +67c47ed commit3ea0fd8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎ruby/0039-combination-sum.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defcombination_sum(candidates,target)
2+
@result=[]
3+
@target=target
4+
@candidates=candidates
5+
defdfs(i,current,total)
6+
iftotal ==@target
7+
@result.append(current.dup())
8+
return
9+
end
10+
ifi >=@candidates.length() ||total >@target
11+
return
12+
end
13+
14+
current.append(@candidates[i])
15+
dfs(i,current,total+@candidates[i])
16+
current.pop()
17+
dfs(i+1,current,total)
18+
end
19+
20+
dfs(0,[],0)
21+
return@result
22+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp