Skip to content

Commit 072cc76

Browse files
committed
[20251115] PGM / LV2 / 타겟 넘버 / 김민진
1 parent 80fb9e7 commit 072cc76

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
```java
2+
public class PGM_LV2_타겟_넘버 {
3+
4+
private static int target, len, ans;
5+
private static int[] nums;
6+
7+
private static void dfs(int start, int sum) {
8+
if (start == len) {
9+
if (sum == target) ans++;
10+
return;
11+
}
12+
13+
dfs(start + 1, sum - nums[start]);
14+
dfs(start + 1, sum + nums[start]);
15+
}
16+
17+
public int solution(int[] n, int t) {
18+
target = t;
19+
nums = n;
20+
len = n.length;
21+
ans = 0;
22+
23+
dfs(0, 0);
24+
25+
return ans;
26+
}
27+
28+
}
29+
```

0 commit comments

Comments
 (0)