add: 220428-CN [cpp]
This commit is contained in:
parent
8c0ffa7567
commit
ca16bc6381
|
|
@ -0,0 +1,18 @@
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 905. Sort Array By Parity
|
||||||
|
* Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers.
|
||||||
|
* Return any array that satisfies this condition.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
std::vector<int> sortArrayByParity(std::vector<int>& nums) {
|
||||||
|
std::vector<int> e, o;
|
||||||
|
for (int i : nums)
|
||||||
|
((i & 1) ? &o : &e)->push_back(i);
|
||||||
|
e.insert(e.end(), o.begin(), o.end());
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2204)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2204 220427-CN.cpp)
|
ADD_EXECUTABLE(2204 220428-CN.cpp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue