Skip to content

Commit 4705595

Browse files
solves find n unique integers sum up to zero
1 parent 7b03e7f commit 4705595

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [![Java](assets/java.png)](src/ConvertBinaryNumberInLinkedListToInteger.java) | |
336336
| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | | |
337337
| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | |
338-
| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | | |
338+
| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [![Java](assets/java.png)](src/FindNUniqueIntegersSumUpToZero.java) | |
339339
| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | | |
340340
| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | | |
341341
| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class FindNUniqueIntegersSumUpToZero {
2+
public int[] sumZero(int n) {
3+
final int[] result = new int[n];
4+
for (int i = 0, k = 1 ; i + 1 < result.length ; i += 2, k++) {
5+
result[i] = k;
6+
result[i + 1] = -k;
7+
}
8+
if ((n & 1) == 1) result[n - 1] = 0;
9+
return result;
10+
}
11+
}

0 commit comments

Comments
 (0)