algo/di-san-zha-24031/jing-dian--a94a0/yi-ge-fang-93124/ #1507
Replies: 3 comments 3 replies
-
1288一定要合并区间吗?官方解答就没有考虑这种情况 |
Beta Was this translation helpful? Give feedback.
1 reply
-
986 没看懂为什么通过判断区间右端点的大小就能移动指针 |
Beta Was this translation helpful? Give feedback.
1 reply
-
public int removeCoveredIntervals(int[][] intervals) {
if (intervals.length <= 1) return intervals.length;
// start 升序 end 降序
Arrays.sort(intervals, (o1, o2) -> {
if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]);
else return Integer.compare(o2[1], o1[1]);
});
int delCount = 0;
int end = intervals[0][1];
int i = 1;
int n = intervals.length;
while (true) {
while (i < n && intervals[i][1] <= end) {
delCount++;
i++;
}
if (i == intervals.length) break;
end = intervals[i][1];
i++;
}
return intervals.length - delCount;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
algo/di-san-zha-24031/jing-dian--a94a0/yi-ge-fang-93124/
Info 数据结构精品课 (https://aep.h5.xeknow.com/s/1XJHEO) 和 递归算法专题课 (https://aep.xet.tech/s/3YGcq3) 限时附赠网站会员,全新纸质书《labuladong 的算法笔记》 (https://labuladong.gitee.io/algo/images/book/book_i...
https://labuladong.github.io/algo/di-san-zha-24031/jing-dian--a94a0/yi-ge-fang-93124/
Beta Was this translation helpful? Give feedback.
All reactions