题目:769. 最多能完成排序的块
思路:单调栈
class Solution {
public:
int maxChunksToSorted(vector<int>& arr) {
int n = arr.size();
stack<int> monost;
for(int i=0;i<n;++i){
if(monost.empty() || arr[i]>arr[monost.top()]){
monost.push(i);
}else{
int maxm = monost.top();
while(!monost.empty() && arr[i]<arr[monost.top()]){
monost.pop();
}
monost.push(maxm);
}
}
return monost.size();
}
};