当前位置:网站首页>LeetCode 1637. The widest vertical area between two points without any point
LeetCode 1637. The widest vertical area between two points without any point
2022-07-06 16:43:00 【Daylight629】
1637. The widest vertical area between two points without any points
Here you are. n
Points on a two-dimensional plane points
, among points[i] = [xi, yi]
, Please return the point between two points without any point inside The widest vertical area Width .
Vertical area Is defined as a fixed width , and y An area on an axis that extends infinitely ( That is, the height is infinite ). The widest vertical area The vertical area with the largest width .
Please note that , Vertical area On the edge The point of be not in In the area .
Example 1:
Input :points = [[8,7],[9,9],[7,4],[9,7]]
Output :1
explain : The red area and the blue area are both optimal areas .
Example 2:
Input :points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
Output :3
Tips :
n == points.length
2 <= n <= 105
points[i].length == 2
0 <= xi, yi <= 109
Two 、 Method 1
Maximum sorting value , Just look at the abscissa comparison
class Solution {
public int maxWidthOfVerticalArea(int[][] points) {
Arrays.sort(points, (a, b) -> a[0] - b[0]);
int res = 0;
for (int i = 0; i < points.length - 1; i++) {
res = Math.max(res, points[i + 1][0] - points[i][0]);
}
return res;
}
}
Complexity analysis
Time complexity :O(nlogn).
Spatial complexity :O(1).
边栏推荐
- Market trend report, technical innovation and market forecast of China's desktop capacitance meter
- The concept of spark independent cluster worker and executor
- Anaconda下安装Jupyter notebook
- QT realizes window topping, topping state switching, and multi window topping priority relationship
- Summary of FTP function implemented by qnetworkaccessmanager
- Gridhome, a static site generator that novices must know
- 使用jq实现全选 反选 和全不选-冯浩的博客
- Chapter 1 overview of MapReduce
- 我在字节跳动「修电影」
- Research Report on market supply and demand and strategy of China's tetraacetylethylenediamine (TAED) industry
猜你喜欢
Browser print margin, default / borderless, full 1 page A4
第7章 __consumer_offsets topic
Anaconda下安装Jupyter notebook
Chapter 7__ consumer_ offsets topic
ffmpeg命令行使用
Spark independent cluster dynamic online and offline worker node
解决Intel12代酷睿CPU单线程调度问题(二)
解决Intel12代酷睿CPU单线程只给小核运行的问题
两个礼拜速成软考中级软件设计师经验
音视频开发面试题
随机推荐
Chapter 6 datanode
解决Intel12代酷睿CPU单线程只给小核运行的问题
Click QT button to switch qlineedit focus (including code)
QT realizes window topping, topping state switching, and multi window topping priority relationship
软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
LeetCode 1562. Find the latest group of size M
Spark独立集群动态上线下线Worker节点
业务系统兼容数据库Oracle/PostgreSQL(openGauss)/MySQL的琐事
Codeforces Round #800 (Div. 2)AC
Educational Codeforces Round 122 (Rated for Div. 2)
Market trend report, technological innovation and market forecast of double door and multi door refrigerators in China
Installation and configuration of MariaDB
Solve the problem of intel12 generation core CPU [small core full, large core onlookers] (win11)
Chapter 5 yarn resource scheduler
Problem - 1646C. Factorials and Powers of Two - Codeforces
Chapter 2 shell operation of hfds
sublime text 代码格式化操作
Spark's RDD (elastic distributed data set) returns a large result set
Hbuilder x format shortcut key settings
Two weeks' experience of intermediate software designer in the crash soft exam