leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
3016.cpp (412B)
0 class Solution { 1 public: 2 int minimumPushes(const string &word) const { 3 int count[26] = {0}; 4 for (const char c : word) 5 count[c - 'a']++; 6 7 sort(count, count + 26, greater()); 8 9 int res = 0, key = 1, cnt = 0; 10 for (int i = 0; i < 26; i++) { 11 res += key * count[i]; 12 if (++cnt == 8) key++, cnt = 0; 13 } 14 return res; 15 } 16 };