deno.land / x / masx200_leetcode_test@10.6.5 / max-chunks-to-make-sorted-ii / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function maxChunksToSorted(arr: number[]): number { const stack = [] as number[]; for (const val of arr) { if (!stack.length || stack[stack.length - 1] <= val) { stack.push(val); } else { const temp = stack[stack.length - 1]; stack.pop(); while (stack[stack.length - 1] > val) { stack.pop(); } stack.push(temp); } } return stack.length;}export default maxChunksToSorted;
masx200_leetcode_test

Version Info

Tagged at
a year ago