We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9f47b9b commit ddfb81fCopy full SHA for ddfb81f
oh-chaeyeon/7주차_그래프/타켓_넘버.js
@@ -0,0 +1,18 @@
1
+function solution(numbers, target) {
2
+ const dp = new Map();
3
+ dp.set(0, 1);
4
+
5
+ for (const number of numbers) {
6
+ const nextDp = new Map();
7
+ for (const [sum, count] of dp) {
8
+ nextDp.set(sum + number, (nextDp.get(sum + number) || 0) + count);
9
+ nextDp.set(sum - number, (nextDp.get(sum - number) || 0) + count);
10
+ }
11
+ dp.clear();
12
+ for (const [sum, count] of nextDp) {
13
+ dp.set(sum, count);
14
15
16
17
+ return dp.get(target) || 0;
18
+}
0 commit comments