Matej Focko
f0aa77436b
URL: https://leetcode.com/problems/max-chunks-to-make-sorted/ Signed-off-by: Matej Focko <me@mfocko.xyz>
16 lines
336 B
C#
16 lines
336 B
C#
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;
|
|
}
|
|
}
|