标签:
题目:http://www.nowcoder.com/practice/beb5aa231adc45b2a5dcc5b62c93f593
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 };
标签:
原文地址:http://www.cnblogs.com/CheeseZH/p/5113117.html