File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * ๊ฐ๊ฐ ๋ค๋ฅธ ์ ์ ๋ฐฐ์ด candidates์, ๋ชฉํ ์ ์ target์ด ์ฃผ์ด์ง๋ค.
3+ * ๋ฐํํ๋ผ, ํ๊ฒ๊ณผ ๊ฐ์ด ๊ฐ์ ํฉ์ ๋ณด์ ํ ๊ณ ์ ํ ์กฐํฉ์.
4+ * ์กฐํฉ์ ์ด๋ค ์์(any order)๋ก๋ ๋ฐํํ ์ ์์ต๋๋ค.
5+ * ๊ฐ์ ์ซ์๋ฅผ ์ฌ๋ฌ ์กฐํฉ์ ๋ฌด์ ํ(unlimited number of times) ์ธ ์ ์์ต๋๋ค.
6+ * ์ ํํ ์ซ์ ์ค ์ ์ด๋ ํ๋์ ๋น๋๊ฐ ๋ค๋ฅด๋ค๋ฉด ๋ ์กฐํฉ์ ๊ณ ์ ํฉ๋๋ค.
7+ * target์ 150๋ณด๋ค ๋ฎ์ ์ซ์์
๋๋ค.
8+ *
9+ * @param {number[] } candidates
10+ * @param {number } target
11+ * @return {number[][] }
12+ */
13+ var combinationSum = function ( candidates , target ) {
14+ var result = [ ] ;
15+ var nums = [ ] ;
16+ function dfs ( start , total ) {
17+ if ( total > target ) return ;
18+ if ( total === target ) result . push ( nums . slice ( ) ) ;
19+
20+
21+ for ( let i = start ; i < candidates . length ; i ++ ) {
22+ let num = candidates [ i ] ;
23+ nums . push ( num ) ;
24+ dfs ( i , total + num ) ;
25+ nums . pop ( ) ;
26+ }
27+
28+ }
29+ dfs ( 0 , 0 ) ;
30+
31+ return result ;
32+ } ;
You canโt perform that action at this time.
0 commit comments