IT/알고리즘
39★] Leetcode 905. Sort Array By Parity
깻잎쌈
2020. 8. 6. 23:35
반응형
Sort Array By Parity - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
짝수면 앞에 넣어주고, 홀수면 뒤에 넣어주면 된다.
class Solution {
public:
vector<int> sortArrayByParity(vector<int>& A) {
vector<int>ans;
for(int i = 0;i<A.size();i++){
if(A[i] %2 == 0)
ans.insert(ans.begin(), A[i]);
else
ans.push_back(A[i]);
}
return ans;
}
};
반응형