059_任务调度
知识点:统计分析
LeetCode第六百二十一题:https://leetcode-cn.com/problems/task-scheduler/submissions/
本题直接根据题意进行分析,处理好细节就可以。
语言:GoLang
func leastInterval(tasks []byte, n int) int {
static := make([]int, 26)
for _, task := range tasks {
static[task - 'A']++
}
sort.Ints(static)
count := 0
for static[25] > 0 {
for i := 0; i <= n && static[25] > 0; i++ {
if i <= 25 && static[25 - i] > 0 {
static[25 - i]--
}
count++
}
sort.Ints(static)
}
return count
}