put poker on the table
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; }