반응형
class Solution {
public:
vector<int> sumZero(int n) {
vector<int>ans;
if(n%2 == 0){
for(int i = 1;i<=n/2;i++){
ans.push_back(i);
ans.push_back(-i);
}
}
else{
ans.push_back(0);
for(int i = 1;i<=n/2;i++){
ans.push_back(i);
ans.push_back(-i);
}
}
return ans;
}
};
반응형
'IT > 알고리즘' 카테고리의 다른 글
35★] Leetcode 1299. Replace Elements with Greatest Element on Right Side (0) | 2020.07.19 |
---|---|
34] Leetcode 1351. Count Negative Numbers in a Sorted Matrix (0) | 2020.07.19 |
32] Leetcode 807. Max Increase to Keep City Skyline (0) | 2020.07.12 |
31] Leetcode 1512. Number of Good Pairs (0) | 2020.07.12 |
30★★] Leetcode 1010. Pairs of Songs With Total Durations Divisible by 60 (0) | 2020.07.10 |
댓글