C++
1 class Solution { 2 public: 3 void reOrderArray(vector<int> &arr) { 4 vector<int> odd; 5 vector<int> even; 6 for (auto &i: arr) { 7 if (i & 1) { 8 odd.push_back(i); 9 } else { 10 even.push_back(i); 11 } 12 } 13 int i = 0; 14 while (i < odd.size()) { 15 arr[i] = odd[i]; 16 i++; 17 } 18 while (i < arr.size()) { 19 arr[i] = even[i - odd.size()]; 20 i++; 21 } 22 } 23 };
本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/p/5113117.html,如需转载请自行联系原作者