621.task-scheduler.go 243 B

1234567891011121314
  1. func leastInterval(tasks []byte, n int) int {
  2. freq := make([]int, 26)
  3. for _, t := range tasks {
  4. freq[t-'A']++
  5. }
  6. sort.Ints(freq)
  7. max, cnt := freq[25], 0
  8. for _, i := range freq {
  9. if i == max {
  10. cnt++
  11. }
  12. }
  13. return (max-1)*n + cnt
  14. }