diff options
author | terminaldweller <thabogre@gmail.com> | 2022-05-02 14:15:47 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-05-02 14:15:47 +0000 |
commit | 742f5c0074d44cc147ea1832dd8911660022d330 (patch) | |
tree | c82514f2b8ae5be3de160cd27f259f9e9496817d /905/main.cpp | |
parent | update (diff) | |
download | leetcode-742f5c0074d44cc147ea1832dd8911660022d330.tar.gz leetcode-742f5c0074d44cc147ea1832dd8911660022d330.zip |
update
Diffstat (limited to '905/main.cpp')
-rw-r--r-- | 905/main.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/905/main.cpp b/905/main.cpp new file mode 100644 index 0000000..c612f91 --- /dev/null +++ b/905/main.cpp @@ -0,0 +1,36 @@ +#include "header.hpp" + +class Solution { +public: + static std::vector<int> sortArrayByParity(std::vector<int> &nums) { + std::vector<int> result; + int front = 0; + int end = nums.size() - 1; + result.resize(nums.size()); + for (auto &iter : nums) { + if (iter % 2 == 0) { + result[front] = iter; + front++; + } else { + result[end] = iter; + end--; + } + } + for (int i = 0; i < result.size(); ++i) { + std::cout << result[i] << "\n"; + } + return result; + } +}; + +int main(int argc, char **argv) { + std::vector<int> nums = {3, 1, 2, 4}; + std::vector<int> nums2 = {0}; + auto result = Solution::sortArrayByParity(nums); + auto result2 = Solution::sortArrayByParity(nums2); + + for (auto &iter : result) { + std::cout << iter << "\n"; + } + return 0; +} |