c++匿名函数

class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(),intervals.end(),[](vector<int>& a,vector<int>& b){return a[0]<b[0];});
        vector<vector<int>> ans;
        for(auto& val:intervals){
            if(ans.empty()||val[0]>ans.back()[1]){
                ans.push_back(val);
            }
            else{
                int t0=ans.back()[0];
                int t1=ans.back()[1];
                ans.pop_back();
                ans.push_back({t0,max(val[1],t1)});
            }
        }
        return ans;
    }

};

你可能感兴趣的:(c++)