LC.P621[任务调度器] 方法一:桶原理1234567891011121314class Solution { public int leastInterval(char[] tasks, int n) { int[] cnt = new int[26]; int max = 0, total = 0; for (char task : tasks) ++cnt[task - 'A']; for (int i = 0; i < 26; ++i) { max = Math.max(max, cnt[i]); } for (int i = 0; i < 26; ++i) { total += max == cnt[i] ? 1 : 0; } return Math.max(tasks.length, (n + 1) * (max - 1) + total); }} 时间复杂度:$O(n + C)$, $C = 26$ 空间复杂度:$O(C)$