[leetcode] 621 Task Scheduler

来源:互联网 发布:国际米兰数据 编辑:程序博客网 时间:2024/06/07 04:54

【题目描述】

Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.

However, there is a non-negative cooling interval n that means between two same tasks, there must be at least n intervals that CPU are doing different tasks or just be idle.

You need to return the least number of intervals the CPU will take to finish all the given tasks.


1.题目读不懂。

2.参考别人的题解读懂题目以后,自己实现出现的错误:

1)定义了int数组来保存每个task的出现的频度,然后对数组按频度排序,用了sort函数,sort函数的使用错误,sort函数的两个参数一个是数组的开头,一个是数组结尾的下一个位置。

2)没有考虑特殊情况,也就是当task与task之间的间隔为0的时候,会导致之前推倒的公式不满足情况。

原创粉丝点击