public int solution(int[] numbers, int target) {
return dfs(numbers, 0, target, 0, 0);
}
public int dfs(int[] numbers, int depth, int target, int sum, int answer) {
if (depth == numbers.length) {
return (target == sum) ? answer + 1 : answer;
} else {
int result1 = dfs(numbers, depth + 1, target, sum + numbers[depth], answer);
int result2 = dfs(numbers, depth + 1, target, sum - numbers[depth], answer);
return result1 + result2;
}
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/43165