Leetcode-922 Sort Array By Parity II(按奇偶排序数组 II)

 1 class Solution
 2 {
 3     public:
 4         vector<int> sortArrayByParityII(vector<int>& A)
 5         {
 6             stack<int> oddList;
 7             stack<int> evenList;
 8             
 9             for(auto d:A)
10                 if((d&0x1)==1)
11                     oddList.push(d);
12                 else
13                     evenList.push(d);
14             
15             vector<int> result;
16             while(!oddList.empty())
17             {
18                 result.push_back(evenList.top());
19                 result.push_back(oddList.top());
20                 evenList.pop();
21                 oddList.pop();
22             }
23             return result;
24         }
25 };

 

posted @ 2018-10-16 18:31  Asurudo  阅读(167)  评论(0编辑  收藏  举报