mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	国外版
This commit is contained in:
		
							
								
								
									
										48
									
								
								算法题(国外版)/task-scheduler.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								算法题(国外版)/task-scheduler.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
<p>Given a characters array <code>tasks</code>, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.</p>
 | 
			
		||||
 | 
			
		||||
<p>However, there is a non-negative integer <code>n</code> that represents the cooldown period between two <b>same tasks</b> (the same letter in the array), that is that there must be at least <code>n</code> units of time between any two same tasks.</p>
 | 
			
		||||
 | 
			
		||||
<p>Return <em>the least number of units of times that the CPU will take to finish all the given tasks</em>.</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> tasks = ["A","A","A","B","B","B"], n = 2
 | 
			
		||||
<strong>Output:</strong> 8
 | 
			
		||||
<strong>Explanation:</strong> 
 | 
			
		||||
A -> B -> idle -> A -> B -> idle -> A -> B
 | 
			
		||||
There is at least 2 units of time between any two same tasks.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 2:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> tasks = ["A","A","A","B","B","B"], n = 0
 | 
			
		||||
<strong>Output:</strong> 6
 | 
			
		||||
<strong>Explanation:</strong> On this case any permutation of size 6 would work since n = 0.
 | 
			
		||||
["A","A","A","B","B","B"]
 | 
			
		||||
["A","B","A","B","A","B"]
 | 
			
		||||
["B","B","B","A","A","A"]
 | 
			
		||||
...
 | 
			
		||||
And so on.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 3:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2
 | 
			
		||||
<strong>Output:</strong> 16
 | 
			
		||||
<strong>Explanation:</strong> 
 | 
			
		||||
One possible solution is
 | 
			
		||||
A -> B -> C -> A -> D -> E -> A -> F -> G -> A -> idle -> idle -> A -> idle -> idle -> A
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Constraints:</strong></p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li><code>1 <= task.length <= 10<sup>4</sup></code></li>
 | 
			
		||||
	<li><code>tasks[i]</code> is upper-case English letter.</li>
 | 
			
		||||
	<li>The integer <code>n</code> is in the range <code>[0, 100]</code>.</li>
 | 
			
		||||
</ul>
 | 
			
		||||
		Reference in New Issue
	
	Block a user