Skip to content

Commit 7e19890

Browse files
committed
Runtime: 3 ms (Top 37.27%) | Memory: 7.30 MB (Top 15.48%)
1 parent f56482d commit 7e19890

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1+
// Runtime: 3 ms (Top 37.27%) | Memory: 7.30 MB (Top 15.48%)
2+
13
class Solution {
24
public:
35
vector<int> sumZero(int n) {
4-
if(n == 1){
5-
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-
}else{
13-
res.push_back(i);
14-
continue;
15-
}
16-
}
17-
res.push_back(i);
18-
}
19-
return res;
6+
vector<int>ans;
7+
for(int i=1;i<=n/2;i++)
8+
{
9+
ans.push_back(-i);
10+
ans.push_back(i);
2011
}
12+
if(n%2==1)
13+
ans.push_back(0);
14+
return ans;
2115
}
2216
};

0 commit comments

Comments
 (0)