Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int max(int a, int b){
- return (a > b) ? a:b;
- }
- int leastInterval(vector<char>& tasks, int n) {
- int maxCount, ans;
- maxCount = ans = 0;
- unordered_map<char, int> m;
- for(auto c: tasks){
- m[c]++;
- maxCount = max(maxCount, m[c]);
- }
- ans = (maxCount-1)*(n+1);
- for(auto c: m){
- if(c.second == maxCount) ans++;
- }
- ans = max(ans, tasks.size());
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement