# 295. 交集

## 描述

• 1 <= len(a),len(b) <= 1e5
• abs(max(a)) <= 1e9

## 样例 1：

输入:
a = [[0,3], [7,10]] , b = [[-1,1],[2,8]]

ans = [[0,0],[0,1],[1,1]]


# 题解

public class Solution {
/**
* @param a: first sequence
* @param b: second sequence
* @return: return ans
*/
public List<List<Integer>> Intersection(List<List<Integer>> a, List<List<Integer>> b) {

List<List<Integer>> ret = new ArrayList<>();

if (a == null
|| b == null
|| a.isEmpty()
|| b.isEmpty()) {
return ret;
}

Iterator<List<Integer>> iteratorA = a.iterator();
Iterator<List<Integer>> iteratorB = b.iterator();

List<Integer> rowA = iteratorA.next();
List<Integer> rowB = iteratorB.next();

int indexA = 0;
int indexB = 0;

int a0 = rowA.get(0);
int a1 = rowA.get(1);
int b0 = rowB.get(0);
int b1 = rowB.get(1);

while (true) {

if ((a0 >= b0
&& a0 <= b1)
|| (b0 >= a0
&& b0 <= a1)) {
List<Integer> r = new ArrayList<>();
}

if (a1 <= b1
&& iteratorA.hasNext()) {
++indexA;
rowA = iteratorA.next();
a0 = rowA.get(0);
a1 = rowA.get(1);
} else if (b1 <= a1 && iteratorB.hasNext()) {
++indexB;
rowB = iteratorB.next();
b0 = rowB.get(0);
b1 = rowB.get(1);
} else {
return ret;
}
}
}
}


# 鸣谢

• 点赞 1
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 打赏

打赏

二当家的白帽子

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 举报
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文