Find N Unique Integers Sum up to Zero LeetCode solution in Java

1
class Solution {
2
public int[] sumZero(int n) {
3
int[] ans = new int[n];
4
int j = 0;
5

6
for (int i = 1; i <= n / 2; i++) {
7
ans[j] = i;
8
j++;
9
}
10
for (int i = 1; i <= n / 2; i++) {
11
ans[j] = -i;
12
j++;
13
}
14
if (n % 2 != 0) ans[j] = 0;
15

16
return ans;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0