首页 > 编程语言 > 详细

[数组] leetcode 950 Reveal Cards In Increasing Order

时间:2019-08-01 20:48:02      阅读:79      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!