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)


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