# 0769. Max Chunks To Make Sorted
###### tags: `Leetcode` `Microsoft` `Medium`
Link: https://leetcode.com/problems/max-chunks-to-make-sorted/
## 思路
非常tricky的一道题
要注意这题的**数组里面只有0~k-1**
首先找到从左块开始最小块的大小。如果前 k 个元素为 [0, 1, ..., k-1],可以直接把他们分为一个块。当我们需要检查 [0, 1, ..., n-1] 中前 k+1 个元素是不是 [0, 1, ..., k] 的时候,只需要检查其中最大的数是不是 k 就可以了。
## Code
```java=
class Solution {
public int maxChunksToSorted(int[] arr) {
int res = 0, max = 0;
for(int i = 0;i < arr.length;i++){
max = Math.max(max, arr[i]);
if(max == i){
res++;
}
}
return res;
}
}
```
## Result
Runtime: 0 ms, faster than **100.00%** of Java online submissions for Max Chunks To Make Sorted.
Memory Usage: 36.1 MB, less than **78.92%** of Java online submissions for Max Chunks To Make Sorted.