class Solution {
int answer = 0;
public int solution(int[] numbers, int target) {
DFS(numbers, 0, target, 0);
return answer;
}
public void DFS(int[] numbers, int depth, int target, int result){
if(numbers.length == depth){
if(target == result) answer++;
}
else{
DFS(numbers, depth+1, target, result + numbers[depth]);
DFS(numbers, depth+1, target, result - numbers[depth]);
}
}
}
'공부기록 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 최솟값 만들기 (0) | 2023.10.29 |
---|---|
[프로그래머스] 최소 직사각형 (0) | 2023.10.28 |
[프로그래머스] K번째 수 (0) | 2023.10.17 |
[프로그래머스] 카드 뭉치 (0) | 2023.10.15 |
[프로그래머스] MySQL (정리중) (0) | 2023.10.13 |