aboutsummaryrefslogtreecommitdiffstats
path: root/905/main.cpp
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-05-02 14:15:47 +0000
committerterminaldweller <thabogre@gmail.com>2022-05-02 14:15:47 +0000
commit742f5c0074d44cc147ea1832dd8911660022d330 (patch)
treec82514f2b8ae5be3de160cd27f259f9e9496817d /905/main.cpp
parentupdate (diff)
downloadleetcode-742f5c0074d44cc147ea1832dd8911660022d330.tar.gz
leetcode-742f5c0074d44cc147ea1832dd8911660022d330.zip
update
Diffstat (limited to '')
-rw-r--r--905/main.cpp36
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;
+}