Skip to content

Commit 7da1019

Browse files
authored
Create 1304-find-n-unique-integers-sum-up-to-zero.js
1 parent 62c3958 commit 7da1019

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number} n
3+
* @return {number[]}
4+
*/
5+
const sumZero = function(n) {
6+
const num = ~~(n / 2)
7+
const odd = n % 2 === 1
8+
const res = pair(num)
9+
if(odd) res.push(0)
10+
return res
11+
};
12+
13+
function pair(num) {
14+
const set = new Set()
15+
const res = []
16+
for(let i = 1; i <= num; i++) res.push(i, -i)
17+
return res
18+
}

0 commit comments

Comments
 (0)