File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // ! ๋์ค์ ๋ค์ ํ์ด์ผ ํ ๋ฌธ์
2+ //! 30๋ถ ๋ด์ ํ์ง ๋ชปํด์ AI์ ๋์์ ๋ฐ์ ๊ตฌํํ์ต๋๋ค..
3+ // recursion์ ์ฌ์ฉ, ์ข
๋ฃ ์กฐ๊ฑด ๋ฑ ์ด๋์ ๋ ๊ทผ์ ํ ์์ด๋์ด๋ฅผ ๊ตฌํํ์ง๋ง,
4+ // idx๋ฅผ ๋๊ธฐ์ง ์๊ณ number๋ฅผ ์ง์ ๋๊ธฐ๋ ค๊ณ ํ๋ ๋ถ๋ถ์ด๋, results pop์ ๋์ณค๋ ๋ถ๋ถ ๋ฑ์ด ์์ต๋๋ค.
5+ const combinationSum = function ( candidates , target ) {
6+ const answer = [ ] ;
7+
8+ function recursion ( idx , target , results = [ ] ) {
9+ if ( target === 0 ) {
10+ answer . push ( [ ...results ] ) ;
11+ return ;
12+ }
13+ if ( target < 0 ) return ;
14+
15+ for ( let i = idx ; i < candidates . length ; i ++ ) {
16+ results . push ( candidates [ i ] ) ;
17+ recursion ( i , target - candidates [ i ] , results ) ;
18+ results . pop ( ) ;
19+ }
20+ }
21+ recursion ( 0 , target , [ ] ) ;
22+
23+ return answer ;
24+ } ;
You canโt perform that action at this time.
0 commit comments