leetcode

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

3016.cpp (412B)


      1 class Solution {
      2   public:
      3     int minimumPushes(const string &word) const {
      4         int count[26] = {0};
      5         for (const char c : word)
      6             count[c - 'a']++;
      7 
      8         sort(count, count + 26, greater());
      9 
     10         int res = 0, key = 1, cnt = 0;
     11         for (int i = 0; i < 26; i++) {
     12             res += key * count[i];
     13             if (++cnt == 8) key++, cnt = 0;
     14         }
     15         return res;
     16     }
     17 };