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)


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