Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe172dd

Browse files
Find N Unique Integers Sum up to Zero
1 parent f5c399e commit fe172dd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Link: https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/
2+
Language: C#
3+
4+
5+
6+
7+
8+
9+
10+
public class Solution {
11+
public int[] SumZero(int n)
12+
{
13+
int[] nums = new int[n];
14+
int index = 0;
15+
16+
if (n % 2 != 0)
17+
{
18+
nums[0] = 0;
19+
index++;
20+
}
21+
22+
for (int i = 1; i < nums.Length; i += 2)
23+
{
24+
nums[index] = i;
25+
index++;
26+
nums[index] = i * -1;
27+
index++;
28+
}
29+
30+
return nums;
31+
}
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /