leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0950.cpp (558B)


      1 class Solution {
      2   public:
      3     vector<int> deckRevealedIncreasing(vector<int> &deck) {
      4         sort(deck.begin(), deck.end(), [](const int a, const int b) { return a > b; });
      5         deque<int> q;
      6         vector<int> res;
      7 
      8         for (int i = 0; i < deck.size() - 1; i++) {
      9             q.push_back(deck[i]);
     10             q.push_back(q.front());
     11             q.pop_front();
     12         }
     13         q.push_back(deck[deck.size() - 1]);
     14 
     15         while (!q.empty()) {
     16             res.push_back(q.back());
     17             q.pop_back();
     18         }
     19         return res;
     20     }
     21 };