mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>假设有 <code>n</code><strong> </strong>台超级洗衣机放在同一排上。开始的时候,每台洗衣机内可能有一定量的衣服,也可能是空的。</p>
 | 
						||
 | 
						||
<p>在每一步操作中,你可以选择任意 <code>m</code> (<code>1 <= m <= n</code>) 台洗衣机,与此同时将每台洗衣机的一件衣服送到相邻的一台洗衣机。</p>
 | 
						||
 | 
						||
<p>给定一个整数数组 <code>machines</code> 代表从左至右每台洗衣机中的衣物数量,请给出能让所有洗衣机中剩下的衣物的数量相等的 <strong>最少的操作步数 </strong>。如果不能使每台洗衣机中衣物的数量相等,则返回 <code>-1</code> 。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>machines = [1,0,5]
 | 
						||
<strong>输出:</strong>3
 | 
						||
<strong>解释:</strong>
 | 
						||
第一步:    1     0 <-- 5    =>    1     1     4
 | 
						||
第二步:    1 <-- 1 <-- 4    =>    2     1     3    
 | 
						||
第三步:    2     1 <-- 3    =>    2     2     2   
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>machines = [0,3,0]
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>
 | 
						||
第一步:    0 <-- 3     0    =>    1     2     0    
 | 
						||
第二步:    1     2 --> 0    =>    1     1     1     
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>machines = [0,2,0]
 | 
						||
<strong>输出:</strong>-1
 | 
						||
<strong>解释:</strong>
 | 
						||
不可能让所有三个洗衣机同时剩下相同数量的衣物。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>n == machines.length</code></li>
 | 
						||
	<li><code>1 <= n <= 10<sup>4</sup></code></li>
 | 
						||
	<li><code>0 <= machines[i] <= 10<sup>5</sup></code></li>
 | 
						||
</ul>
 |