Skip to content

Commit 7065809

Browse files
authored
Create find-n-unique-integers-sum-up-to-zero.cpp
1 parent de605d0 commit 7065809

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
vector<int> sumZero(int n) {
7+
vector<int> result;
8+
for (int i = -(n / 2); i <= (n / 2); ++i) {
9+
if (i == 0 && n % 2 == 0) {
10+
continue;
11+
}
12+
result.emplace_back(i);
13+
}
14+
return result;
15+
}
16+
};

0 commit comments

Comments
 (0)