986. Interval List Intersections

https://leetcode-cn.com/problems/interval-list-intersections/

986. Interval List Intersections

class Solution {
public:


	vector<vector<int>> intervalIntersection(vector<vector<int>>& A, vector<vector<int>>& B) {
		int i = 0, j = 0;
		vector<vector<int>> ans;
		while (i<A.size()&&j<B.size()){
			int left = max(A[i][0], B[j][0]);
			int right = min(A[i][1], B[j][1]);
			if (right >= left) {
				ans.push_back({ left,right });
			}
			if (A[i][1] < B[j][1]) {
				++i;
			}
			else ++j;
		}

		return ans;
	}
};
上一篇:接口流量统计间隔调整


下一篇:[LeetCode] 436. Find Right Interval