[LeetCode]Find Right Interval(Java)
来源:互联网 发布:c语言编译环境 编辑:程序博客网 时间:2024/05/17 22:18
这道题又涨姿势了,treemap自带接口方法lowerEntry、floorEntry、ceilingEntry和higherEntry分别返回与小于、小于等于、大于等于、大于给定键的键关联的Map.Entry对象,如果不存在这样的键,则返回null。类似地,方法lowerKey、floorKey、ceilingKey和higherKey只返回关联的键。
public class Solution { public int[] findRightInterval(Interval[] intervals) { int[] result = new int[intervals.length]; java.util.NavigableMap<Integer, Integer> intervalMap = new TreeMap<>(); for (int i = 0; i < intervals.length; ++i) { intervalMap.put(intervals[i].start, i); } for (int i = 0; i < intervals.length; ++i) { Map.Entry<Integer, Integer> entry = intervalMap.ceilingEntry(intervals[i].end); result[i] = (entry != null) ? entry.getValue() : -1; } return result; }}
我的方法比较土就是暴力解时间复杂度O(n2)后来看到有人在查找的时候用二分查找时间复杂度为O(nlogn)跟上述复杂度一样
2017/03/13
0 0
- [LeetCode]Find Right Interval(Java)
- Leetcode Find Right Interval
- LeetCode 436. Find Right Interval
- [Leetcode] 436. Find Right Interval
- [leetcode]436. Find Right Interval
- Leetcode 436. Find Right Interval
- LeetCode 436. Find Right Interval
- Leetcode-436. Find Right Interval
- [LeetCode]436. Find Right Interval
- leetcode 436. Find Right Interval
- leetcode 436. Find Right Interval
- leetcode题解-436. Find Right Interval
- [Leetcode] 436. Find Right Interval 解题报告
- 436. Find Right Interval
- 436. Find Right Interval
- Find Right Interval
- 436. Find Right Interval
- 436. Find Right Interval
- 86- 条件变量 condition
- TensorFlow 学习(三)—— Variables(tf.initialize_all_variables()/tf.global_variables_initializer())
- My First Dome
- Leetcode刷题(4)
- RecycleView的实现
- [LeetCode]Find Right Interval(Java)
- 入手树莓派
- CodeForces 780B The Meeting Place Cannot Be Changed【二分】
- 网络获取数据sd卡读取
- 密码学之凯撒加密解密算法
- 使用 ffmpeg 进行网络推流:拉流->解封装->解码->处理原始数据(音频、视频)->编码->编码->推流
- Linux apache下导入SSL证书
- 《剑指offer》数组——二维数组中查找
- 如何使用Androidstudio实现中英手机信息页面