
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
public class Solution
{
private int answer = 0;
public int solution(int[] numbers, int target)
{
DFS(0, -1, numbers, target);
return answer;
}
private void DFS(int sum, int index, int[] numbers, int target)
{
//꼭 배열을 다 순회해야한다.
if (index + 1 >= numbers.Length)
{
if (sum == target)
answer++;
return;
}
index++;
DFS(sum + numbers[index], index, numbers, target);
DFS(sum - numbers[index], index, numbers, target);
}
}
|
cs |
'프로그래머스 > 프로그래머스 Lv2' 카테고리의 다른 글
| [C#]프로그래머스/최댓값과 최솟값 (0) | 2023.05.28 |
|---|---|
| [C#]프로그래머스/큰 수 만들기/그리디 (0) | 2023.04.26 |
| [C#]프로그래머스/거리두기 확인/BFS (0) | 2023.04.21 |
| [C#]프로그래머스/호텔 대실 (0) | 2023.04.20 |
| 프로그래머스/연속된 부분 수열의 합 (0) | 2023.04.15 |