We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f56482d commit 7e19890Copy full SHA for 7e19890
scripts/algorithms/F/Find N Unique Integers Sum up to Zero/Find N Unique Integers Sum up to Zero.cpp
@@ -1,22 +1,16 @@
1
+// Runtime: 3 ms (Top 37.27%) | Memory: 7.30 MB (Top 15.48%)
2
+
3
class Solution {
4
public:
5
vector<int> sumZero(int n) {
- if(n == 1){
- return {0};
6
- }else{
7
- vector<int> res;
8
- for(int i=n/2*-1;i<=n/2;i++){
9
- if(i == 0){
10
- if(n%2 == 0){
11
- continue;
12
13
- res.push_back(i);
14
15
- }
16
17
18
19
- return res;
+ vector<int>ans;
+ for(int i=1;i<=n/2;i++)
+ {
+ ans.push_back(-i);
+ ans.push_back(i);
20
}
+ if(n%2==1)
+ ans.push_back(0);
+ return ans;
21
22
};
0 commit comments