LeetCode/cs/max-chunks-to-make-sorted.cs

17 lines
336 B
C#
Raw Normal View History

public class Solution {
public int MaxChunksToSorted(int[] arr) {
var chunks = 0;
var maximum = arr[0];
for (int i = 0; i < arr.Length; ++i) {
maximum = Math.Max(maximum, arr[i]);
if (maximum == i) {
++chunks;
}
}
return chunks;
}
}