mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			35 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given an integer array <code>arr</code>.</p>
 | 
						|
 | 
						|
<p>We split <code>arr</code> into some number of <strong>chunks</strong> (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.</p>
 | 
						|
 | 
						|
<p>Return <em>the largest number of chunks we can make to sort the array</em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> arr = [5,4,3,2,1]
 | 
						|
<strong>Output:</strong> 1
 | 
						|
<strong>Explanation:</strong>
 | 
						|
Splitting into two or more chunks will not return the required result.
 | 
						|
For example, splitting into [5, 4], [3, 2, 1] will result in [4, 5, 1, 2, 3], which isn't sorted.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong>Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> arr = [2,1,3,4,4]
 | 
						|
<strong>Output:</strong> 4
 | 
						|
<strong>Explanation:</strong>
 | 
						|
We can split into two chunks, such as [2, 1], [3, 4, 4].
 | 
						|
However, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= arr.length <= 2000</code></li>
 | 
						|
	<li><code>0 <= arr[i] <= 10<sup>8</sup></code></li>
 | 
						|
</ul>
 |