problem:https://leetcode.com/problems/reveal-cards-in-increasing-order/
我的思路先排序,然后反向模拟整个过程,按从大大小的顺序放入数据,每次放入之前,把最后一个数字挪到前面来。
class Solution { public: vector<int> deckRevealedIncreasing(vector<int>& deck) { deque<int> arr; sort(deck.begin(), deck.end()); for(int i = deck.size() - 1;i >= 0 ;i--) { if(arr.size() >= 1) { int num = arr.back(); arr.pop_back(); arr.push_front(num); } arr.push_front(deck[i]); } vector<int> res; while(arr.size()) { res.push_back(arr.front()); arr.pop_front(); } return res; } };
[数组] leetcode 950 Reveal Cards In Increasing Order
原文:https://www.cnblogs.com/fish1996/p/11285165.html