Skip to content

Commit adeda9d

Browse files
committed
[PGS] 타겟넘버 / Level 2 / 30분 / 성공
1 parent c6c2522 commit adeda9d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
int count = 0;
3+
4+
public int solution(int[] numbers, int target) {
5+
backtracking(0, 0, numbers, target);
6+
7+
return count;
8+
}
9+
10+
public void backtracking(int idx, int currSum, int[] numbers, int target) {
11+
if (idx == numbers.length) {
12+
if (currSum == target) count++;
13+
return;
14+
}
15+
16+
backtracking(idx + 1, currSum + numbers[idx], numbers, target);
17+
backtracking(idx + 1, currSum - numbers[idx], numbers, target);
18+
}
19+
}

0 commit comments

Comments
 (0)