Skip to content

Latest commit

 

History

History
21 lines (20 loc) · 571 Bytes

621.md

File metadata and controls

21 lines (20 loc) · 571 Bytes
// c[25] - 1 是n个块,n+1是每块中的个数, 25 - i是最后那一个不算快的长度,感觉解法很简单,但是就是想不到这么妙的解法
/**
 * @param {character[]} tasks
 * @param {number} n
 * @return {number}
 */
const leastInterval1 = function (tasks, n) {
  let c = new Array(26);
  c.fill(0);
  for (t of tasks) {
    ++c[t.charCodeAt() - 65];
  }
  c.sort((a, b) => a - b)
  let i = 25;
  while (i >= 0 && c[i] == c[25]) i--;
  return Math.max(tasks.length, (c[25] - 1) * (n + 1) + 25 - i);
};

leastInterval('AAAABBBEEFFGG', 3)