From ca16bc63815ece9f97da58406a09cdfd34348c22 Mon Sep 17 00:00:00 2001 From: eat-swap Date: Thu, 28 Apr 2022 00:15:36 +0800 Subject: [PATCH] add: 220428-CN [cpp] --- cpp/2204/220428-CN.cpp | 18 ++++++++++++++++++ cpp/2204/CMakeLists.txt | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 cpp/2204/220428-CN.cpp diff --git a/cpp/2204/220428-CN.cpp b/cpp/2204/220428-CN.cpp new file mode 100644 index 0000000..0bcafa9 --- /dev/null +++ b/cpp/2204/220428-CN.cpp @@ -0,0 +1,18 @@ +#include + +/** + * 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 sortArrayByParity(std::vector& nums) { + std::vector e, o; + for (int i : nums) + ((i & 1) ? &o : &e)->push_back(i); + e.insert(e.end(), o.begin(), o.end()); + return e; + } +}; diff --git a/cpp/2204/CMakeLists.txt b/cpp/2204/CMakeLists.txt index d8d4641..ab3b438 100644 --- a/cpp/2204/CMakeLists.txt +++ b/cpp/2204/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2204) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2204 220427-CN.cpp) +ADD_EXECUTABLE(2204 220428-CN.cpp)