Skip to content

Commit 4cc360d

Browse files
committed
�¢寃� �� / 以�
1 parent 0a7e960 commit 4cc360d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

JustDevRae/Graph/target_number.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function solution(numbers, target) {
2+
let count = 0;
3+
4+
function DFS(index, currentSum) {
5+
if (index === numbers.length) {
6+
if (currentSum === target) count++;
7+
return;
8+
}
9+
10+
DFS(index + 1, currentSum + numbers[index]);
11+
DFS(index + 1, currentSum - numbers[index]);
12+
}
13+
14+
DFS(0, 0);
15+
16+
return count;
17+
}

0 commit comments

Comments
 (0)