YEZAELP

LeetCode: Reveal Cards In Increasing Order

Nov 21st, 2021 (edited)
242
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     vector<int> deckRevealedIncreasing(vector<int>& deck) {
  4.         sort(deck.begin(), deck.end());
  5.         int sz = deck.size();
  6.         deque <int> dq;
  7.         for(int i=sz-1;i>=0;i--){
  8.             if(i < sz-1){
  9.                 dq.push_front(dq.back());
  10.                 dq.pop_back();
  11.             }
  12.             dq.push_front(deck[i]);
  13.         }
  14.         vector <int> ans;
  15.         while(!dq.empty()){
  16.             ans.push_back(dq.front());
  17.             dq.pop_front();
  18.         }
  19.         return ans;
  20.     }
  21. };
RAW Paste Data Copied