leetcode

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

0895.cpp (418B)


      1 class FreqStack {
      2     unordered_map<int, int> count;
      3     vector<int> track[20001];
      4     int maxi = 0;
      5 
      6   public:
      7     void push(int val) {
      8         const int cnt = ++count[val];
      9         track[cnt].push_back(val);
     10         maxi = max(maxi, cnt);
     11     }
     12 
     13     int pop() {
     14         const int res = track[maxi].back();
     15         track[maxi].pop_back();
     16         if (track[count[res]--].empty()) maxi--;
     17         return res;
     18     }
     19 };