Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.1020 (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Sep 23, 2024
1 parent 44b8480 commit 4fab89d
Show file tree
Hide file tree
Showing 27 changed files with 432 additions and 770 deletions.
52 changes: 28 additions & 24 deletions solution/0600-0699/0621.Task Scheduler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,37 @@ tags:

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

<pre>
<strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 2
<strong>输出:</strong>8
<strong>解释:</strong>A -&gt; B -&gt; (待命) -&gt; A -&gt; B -&gt; (待命) -&gt; A -&gt; B
在本示例中,两个相同类型任务之间必须间隔长度为 n = 2 的冷却时间,而执行一个任务只需要一个单位时间,所以中间出现了(待命)状态。 </pre>

<p><strong>示例 2:</strong></p>

<pre>
<strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 0
<strong>输出:</strong>6
<strong>解释:</strong>在这种情况下,任何大小为 6 的排列都可以满足要求,因为 n = 0
["A","A","A","B","B","B"]
["A","B","A","B","A","B"]
["B","B","B","A","A","A"]
...
诸如此类
</pre>
<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>

<pre>
<strong>输入:</strong>tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2
<strong>输出:</strong>16
<strong>解释:</strong>一种可能的解决方案是:
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
</pre>
<div class="example-block"><strong>输入:</strong>tasks = ["A","A","A","B","B","B"], n = 0</div>

<div class="example-block"><strong>输出:</strong>6</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>

Expand Down
6 changes: 3 additions & 3 deletions solution/0600-0699/0621.Task Scheduler/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ tags:

<!-- description:start -->

<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>
<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>

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

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

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

<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>
<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>
</div>

<p><strong class="example">Example 2:</strong></p>
Expand Down
4 changes: 2 additions & 2 deletions solution/0600-0699/0658.Find K Closest Elements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ tags:
<p><strong>示例 2:</strong></p>

<pre>
<strong>输入:</strong>arr = [1,2,3,4,5], k = 4, x = -1
<strong>输出:</strong>[1,2,3,4]
<strong>输入:</strong>arr = [1,1,2,3,4,5], k = 4, x = -1
<strong>输出:</strong>[1,1,2,3]
</pre>

<p>&nbsp;</p>
Expand Down
Loading

0 comments on commit 4fab89d

Please sign in to comment.