首页 > 其他 > 详细

put poker on the table

时间:2020-12-17 21:03:22      阅读:38      评论:0      收藏:0      [点我收藏+]

question description:

技术分享图片

 

 solution with C++:

vector<int> Solution::poker(vector<int> desk) {
    if (desk.size() == 0) {
        return {};
    }
    deque<int> hand;    //手中的牌
    hand.emplace_back(desk[0]);
    int tail;    //手中牌堆最下面的一张牌
    for (int i = 1; i < desk.size(); i++) {
        //将手中牌堆最下面的一张牌,移到最上面
        tail = hand.back();
        hand.pop_back();
        hand.push_front(tail);

        //然后将桌上的牌收回一张到手中,放在手中牌堆的最上面
        hand.push_front(desk[i]);
    }
    
    //将deque转化为vector,然后return
    vector<int> ans;
    while (!hand.empty()) {
        ans.emplace_back(hand.front());
        hand.pop_front();
    }
    return ans;
}

 

put poker on the table

原文:https://www.cnblogs.com/0patrick/p/14151770.html

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