|
@@ -3,12 +3,17 @@ func leastInterval(tasks []byte, n int) int {
|
|
|
for _, t := range tasks {
|
|
|
freq[t-'A']++
|
|
|
}
|
|
|
- sort.Ints(freq)
|
|
|
- max, cnt := freq[25], 0
|
|
|
+ max, cnt := freq[0], 0
|
|
|
for _, i := range freq {
|
|
|
- if i == max {
|
|
|
+ if max < i {
|
|
|
+ max, cnt = i, 1
|
|
|
+ } else if max == i {
|
|
|
cnt++
|
|
|
}
|
|
|
}
|
|
|
- return (max-1)*n + cnt
|
|
|
+ res := (max-1)*(n+1) + cnt
|
|
|
+ if l := len(tasks); res < l {
|
|
|
+ return l // If n is small enough, all tasks can be processed one by one
|
|
|
+ }
|
|
|
+ return res
|
|
|
}
|