leetcode769+划分数组最多多少段,内部排序能成最后的有序数组,有trick

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013554860/article/details/86730851

https://leetcode.com/problems/max-chunks-to-make-sorted/

class Solution {
public:
    int maxChunksToSorted(vector<int>& arr) {
        int res = 0, len = arr.size(), mx = 0;
        for(int i=0; i<len; i++){
            mx = max(mx, arr[i]);
            if(mx==i) res+=1;
        }
        return res;
    }
};

猜你喜欢

转载自blog.csdn.net/u013554860/article/details/86730851