Skip to content

Commit 4fab89d

Browse files
authored
feat: add solutions to lc problem: No.1020 (doocs#3553)
1 parent 44b8480 commit 4fab89d

27 files changed

+432
-770
lines changed

solution/0600-0699/0621.Task Scheduler/README.md

+28-24
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,37 @@ tags:
2929

3030
<p><strong>示例 1:</strong></p>
3131

32-
<pre>
33-
<strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 2
34-
<strong>输出:</strong>8
35-
<strong>解释:</strong>A -&gt; B -&gt; (待命) -&gt; A -&gt; B -&gt; (待命) -&gt; A -&gt; B
36-
在本示例中,两个相同类型任务之间必须间隔长度为 n = 2 的冷却时间,而执行一个任务只需要一个单位时间,所以中间出现了(待命)状态。 </pre>
37-
38-
<p><strong>示例 2:</strong></p>
39-
40-
<pre>
41-
<strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 0
42-
<strong>输出:</strong>6
43-
<strong>解释:</strong>在这种情况下,任何大小为 6 的排列都可以满足要求,因为 n = 0
44-
["A","A","A","B","B","B"]
45-
["A","B","A","B","A","B"]
46-
["B","B","B","A","A","A"]
47-
...
48-
诸如此类
49-
</pre>
32+
<div class="example-block"><strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 2</div>
33+
34+
<div class="example-block"><strong>输出:</strong>8</div>
35+
36+
<div class="example-block"><strong>解释:</strong></div>
37+
38+
<div class="example-block">在完成任务 A 之后,你必须等待两个间隔。对任务 B 来说也是一样。在第 3 个间隔,A 和 B 都不能完成,所以你需要待命。在第 4 个间隔,由于已经经过了 2 个间隔,你可以再次执行 A 任务。</div>
39+
40+
<div class="example-block">&nbsp;</div>
41+
42+
<p><strong class="example">示例 2:</strong></p>
43+
44+
<div class="example-block">
45+
<p><b>输入:</b>tasks = ["A","C","A","B","D","B"], n = 1</p>
46+
47+
<p><b>输出:</b>6</p>
48+
49+
<p><b>解释:</b>一种可能的序列是:A -&gt; B -&gt; C -&gt; D -&gt; A -&gt; B。</p>
50+
51+
<p>由于冷却间隔为 1,你可以在完成另一个任务后重复执行这个任务。</p>
52+
</div>
5053

5154
<p><strong>示例 3:</strong></p>
5255

53-
<pre>
54-
<strong>输入:</strong>tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2
55-
<strong>输出:</strong>16
56-
<strong>解释:</strong>一种可能的解决方案是:
57-
A -&gt; B -&gt; C -&gt; A -&gt; D -&gt; E -&gt; A -&gt; F -&gt; G -&gt; A -&gt; (待命) -&gt; (待命) -&gt; A -&gt; (待命) -&gt; (待命) -&gt; A
58-
</pre>
56+
<div class="example-block"><strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 0</div>
57+
58+
<div class="example-block"><strong>输出:</strong>6</div>
59+
60+
<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>
61+
62+
<div class="example-block">只有两种任务类型,A 和 B,需要被 3 个间隔分割。这导致重复执行这些任务的间隔当中有两次待命状态。</div>
5963

6064
<p>&nbsp;</p>
6165

solution/0600-0699/0621.Task Scheduler/README_EN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ tags:
2121

2222
<!-- description:start -->
2323

24-
<p>You are given an array of CPU <code>tasks</code>, each represented by letters&nbsp;A&nbsp;to Z, and a cooling time, <code>n</code>. Each cycle or interval allows the completion of one task. Tasks can be completed in any order, but there&#39;s a constraint: <strong>identical</strong> tasks must be separated by at least <code>n</code> intervals due to cooling time.</p>
24+
<p>You are given an array of CPU <code>tasks</code>, each labeled with a letter from A to Z, and a number <code>n</code>. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there&#39;s a constraint: there has to be a gap of <strong>at least</strong> <code>n</code> intervals between two tasks with the same label.</p>
2525

26-
<p>Return the <em>minimum number of intervals</em> required to complete all tasks.</p>
26+
<p>Return the <strong>minimum</strong> number of CPU intervals required to complete all tasks.</p>
2727

2828
<p>&nbsp;</p>
2929
<p><strong class="example">Example 1:</strong></p>
@@ -50,7 +50,7 @@ font-size: 0.85rem;
5050

5151
<p><strong>Explanation:</strong> A possible sequence is: A -&gt; B -&gt; idle -&gt; A -&gt; B -&gt; idle -&gt; A -&gt; B.</p>
5252

53-
<p>After completing task A, you must wait two cycles before doing A again. The same applies to task B. In the 3<sup>rd</sup> interval, neither A nor B can be done, so you idle. By the 4<sup>th</sup> cycle, you can do A again as 2 intervals have passed.</p>
53+
<p>After completing task A, you must wait two intervals before doing A again. The same applies to task B. In the 3<sup>rd</sup> interval, neither A nor B can be done, so you idle. By the 4<sup>th</sup> interval, you can do A again as 2 intervals have passed.</p>
5454
</div>
5555

5656
<p><strong class="example">Example 2:</strong></p>

solution/0600-0699/0658.Find K Closest Elements/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ tags:
4242
<p><strong>示例 2:</strong></p>
4343

4444
<pre>
45-
<strong>输入:</strong>arr = [1,2,3,4,5], k = 4, x = -1
46-
<strong>输出:</strong>[1,2,3,4]
45+
<strong>输入:</strong>arr = [1,1,2,3,4,5], k = 4, x = -1
46+
<strong>输出:</strong>[1,1,2,3]
4747
</pre>
4848

4949
<p>&nbsp;</p>

0 commit comments

Comments
 (0)