Skip to content

Commit de65f40

Browse files
authored
Create allSubsetSum.js
1 parent 9fcda96 commit de65f40

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/allSubsetSum.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function allSubSetSum(arr = []) {
2+
const set = new Set();
3+
const n = arr.length;
4+
for (let i = 0; i < (1 << n); i++) {
5+
let tmp = 0;
6+
for (let j = 0; j < n; j++) {
7+
if (i & (1 << j) !== 0) tmp += arr[j];
8+
}
9+
set.add(tmp);
10+
}
11+
return set;
12+
};

0 commit comments

Comments
 (0)