๋ฐ์ํ
https://school.programmers.co.kr/learn/courses/30/lessons/43165
ํ์ด
์ฌ๊ทํจ์๋ฅผ ๊ธฐ๋ฐ์ผ๋กํ dfs๋ก ํ์ดํ์๋ค.
let answer = 0;
function dfs(sum, level, numbers, target) {
if(level === numbers.length) {
if(sum === target) {
answer++;
}
return;
}
dfs(sum+numbers[level], level+1, numbers, target);
dfs(sum-numbers[level], level+1, numbers, target);
}
function solution(numbers, target) {
dfs(0, 0, numbers, target);
return answer;
}
๋ฐ์ํ
'๐ ๋ญ? JS๋ก PS๋ฅผ ํ๋ค๊ณ ?' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค][JS / Javascript] [3์ฐจ] ์์ถ (0) | 2023.05.25 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค][JS / Javascript] k์ง์์์ ์์ ๊ฐ์ ๊ตฌํ๊ธฐ (0) | 2023.05.24 |
[ํ๋ก๊ทธ๋๋จธ์ค][JS / Javascript] ์คํ์ฑํ ๋ฐฉ (0) | 2023.05.19 |
[ํ๋ก๊ทธ๋๋จธ์ค][JS / Javascript] ํ๋ก์ธ์ค (0) | 2023.05.18 |
[ํ๋ก๊ทธ๋๋จธ์ค][JS / Javascript] ํํ (1) | 2023.05.17 |