leetcode

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

0621.cpp (514B)


1 class Solution { 2 public: 3 int leastInterval(vector<char> &tasks, int n) { 4 if (n == 0) return tasks.size(); 5 6 vector<int> count(26); 7 for (char t : tasks) 8 count[t - 'A']++; 9 10 int maxi = INT_MIN, cnt = 0; 11 for (int n : count) { 12 if (n == maxi) 13 cnt++; 14 else if (n > maxi) { 15 maxi = n; 16 cnt = 1; 17 } 18 } 19 20 return max((int)tasks.size(), (maxi - 1) * (n + 1) + cnt); 21 } 22 };