1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-05 15:31:43 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/任务调度器 [task-scheduler].html
2025-01-09 20:29:41 +08:00

50 lines
2.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个用字符数组&nbsp;<code>tasks</code> 表示的 CPU 需要执行的任务列表,用字母 A 到 Z 表示,以及一个冷却时间 <code>n</code>。每个周期或时间间隔允许完成一项任务。任务可以按任何顺序完成,但有一个限制:两个<strong> 相同种类</strong> 的任务之间必须有长度为<strong>&nbsp;</strong><code>n</code><strong> </strong>的冷却时间。</p>
<p>返回完成所有任务所需要的<strong> 最短时间间隔</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<div class="example-block"><strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 2</div>
<div class="example-block"><strong>输出:</strong>8</div>
<div class="example-block"><strong>解释:</strong></div>
<div class="example-block">在完成任务 A 之后,你必须等待两个间隔。对任务 B 来说也是一样。在第 3 个间隔A 和 B 都不能完成,所以你需要待命。在第 4 个间隔,由于已经经过了 2 个间隔,你可以再次执行 A 任务。</div>
<div class="example-block">&nbsp;</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><b>输入:</b>tasks = ["A","C","A","B","D","B"], n = 1</p>
<p><b>输出:</b>6</p>
<p><b>解释:</b>一种可能的序列是A -&gt; B -&gt; C -&gt; D -&gt; A -&gt; B。</p>
<p>由于冷却间隔为 1你可以在完成另一个任务后重复执行这个任务。</p>
</div>
<p><strong>示例 3</strong></p>
<div class="example-block"><strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 3</div>
<div class="example-block"><strong>输出:</strong>10</div>
<div class="example-block"><strong>解释:</strong>一种可能的序列为A -&gt; B -&gt; idle -&gt; idle -&gt; A -&gt; B -&gt; idle -&gt; idle -&gt; A -&gt; B。</div>
<div class="example-block">只有两种任务类型A 和 B需要被 3 个间隔分割。这导致重复执行这些任务的间隔当中有两次待命状态。</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= tasks.length &lt;= 10<sup>4</sup></code></li>
<li><code>tasks[i]</code> 是大写英文字母</li>
<li><code>0 &lt;= n &lt;= 100</code></li>
</ul>