945. Task Scheduler

int leastInterval(string &tasks, int n) { // write your code here unordered_map<char, int> mp; int maxL = 0; for(auto i : tasks){ mp[i]++; maxL = max(maxL, mp[i]); } int res = (maxL - 1) * (n + 1); for(auto i : mp){ if(i.second == maxL){ res++; } } return max(res, (int)tasks.size()); }

Comments

Popular posts from this blog

算法的比较