mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定一个长度为 <code>n</code> 的整数数组 <code>arr</code> ,它表示在 <code>[0, n - 1]</code> 范围内的整数的排列。</p>
 | 
						||
 | 
						||
<p>我们将 <code>arr</code> 分割成若干 <strong>块</strong> (即分区),并对每个块单独排序。将它们连接起来后,使得连接的结果和按升序排序后的原数组相同。</p>
 | 
						||
 | 
						||
<p>返回数组能分成的最多块数量。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong> arr = [4,3,2,1,0]
 | 
						||
<strong>输出:</strong> 1
 | 
						||
<strong>解释:</strong>
 | 
						||
将数组分成2块或者更多块,都无法得到所需的结果。
 | 
						||
例如,分成 [4, 3], [2, 1, 0] 的结果是 [3, 4, 0, 1, 2],这不是有序的数组。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong> arr = [1,0,2,3,4]
 | 
						||
<strong>输出:</strong> 4
 | 
						||
<strong>解释:</strong>
 | 
						||
我们可以把它分成两块,例如 [1, 0], [2, 3, 4]。
 | 
						||
然而,分成 [1, 0], [2], [3], [4] 可以得到最多的块数。
 | 
						||
对每个块单独排序后,结果为 [0, 1], [2], [3], [4]
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>n == arr.length</code></li>
 | 
						||
	<li><code>1 <= n <= 10</code></li>
 | 
						||
	<li><code>0 <= arr[i] < n</code></li>
 | 
						||
	<li><code>arr</code> 中每个元素都 <strong>不同</strong></li>
 | 
						||
</ul>
 |