leetcode-----57. 插入区间

代码

class Solution {
public:
    vector<vector<int>> insert(vector<vector<int>>& a, vector<int>& b) {
        vector<vector<int>> ans;
        int k = 0;
        while(k < a.size() && a[k][1] < b[0]) ans.push_back(a[k++]);
        if (k < a.size()) {
            b[0] = min(b[0], a[k][0]);
            while (k < a.size() && a[k][0] <= b[1]) b[1] = max(b[1], a[k++][1]);
        }
        ans.push_back(b);
        while (k < a.size()) ans.push_back(a[k++]);
        return ans;
    }
};
posted @ 2020-07-07 17:05  景云ⁿ  阅读(57)  评论(0编辑  收藏  举报