Skip to content

Commit b52196f

Browse files
committed
Add solution #1304
1 parent 91c7810 commit b52196f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 1304. Find N Unique Integers Sum up to Zero
3+
* https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer n, return any array containing
7+
* n unique integers such that they add up to 0.
8+
*/
9+
10+
/**
11+
* @param {number} n
12+
* @return {number[]}
13+
*/
14+
var sumZero = function(n) {
15+
const result = n % 2 !== 0 ? [0] : [];
16+
while (result.length < n) {
17+
result.push(result.length + 1, (result.length + 1) * -1);
18+
}
19+
return result;
20+
};

0 commit comments

Comments
 (0)