逆向模拟构造题
使用双端队列数据结构。
/*
* @lc app=leetcode id=950 lang=cpp
*
* [950] Reveal Cards In Increasing Order
*/
// @lc code=start
class Solution {
public:
vector<int> deckRevealedIncreasing(vector<int>& deck) {
int N = deck.size();
sort(deck.rbegin(), deck.rend());
deque<int> q;
q.push_front(deck[0]);
int t ;
for(int i=1;i<N;i++){
t = q.back();
q.pop_back();
q.push_front(t);
q.push_front(deck[i]);
}
vector<int> ans(N, 0);
t = 0;
while(!q.empty()){
ans[t++] = q.front();
q.pop_front();
}
return ans;
}
};
// @lc code=end