Skip to content

Commit 41813a4

Browse files
committedJun 14, 2024
Programmers_43165 : 타겟 넘버
1 parent 8b49e00 commit 41813a4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
3+
private int count = 0;
4+
5+
public int solution(int[] numbers, int target) {
6+
dfs(numbers, target, 0, 0);
7+
return count;
8+
}
9+
10+
public void dfs(int[] numbers, int target, int index, int n) {
11+
if(index == numbers.length) {
12+
if(n == target) {
13+
count++;
14+
}
15+
return;
16+
}
17+
18+
dfs(numbers, target, index+1, n + numbers[index]);
19+
dfs(numbers, target, index+1, n - numbers[index]);
20+
}
21+
}

0 commit comments

Comments
 (0)
Please sign in to comment.