short c++ solution


  • 0
    D
    int leastInterval(vector<char>& tasks, int n) {
        int freq[26];
        fill(begin(freq), end(freq), 0);
        for (auto t : tasks) freq[t - 'A']++;
        int maxFreq = *max_element(begin(freq), end(freq));
        int maxFreqCount = count(begin(freq), end(freq), maxFreq);
        int numTasks = tasks.size();
        return max((maxFreq - 1) * (n + 1) + maxFreqCount, numTasks);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.