cs: add «769. Max Chunks To Make Sorted»
URL: https://leetcode.com/problems/max-chunks-to-make-sorted/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
52a993ea87
commit
f0aa77436b
1 changed files with 16 additions and 0 deletions
16
cs/max-chunks-to-make-sorted.cs
Normal file
16
cs/max-chunks-to-make-sorted.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue