当前位置:网站首页>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).
边栏推荐
- Codeforces Round #799 (Div. 4)A~H
- Cmake Express
- Research Report on market supply and demand and strategy of China's four seasons tent industry
- Advancedinstaller installation package custom action open file
- (lightoj - 1349) Aladdin and the optimal invitation (greed)
- Market trend report, technical innovation and market forecast of tabletop dishwashers in China
- Kubernetes cluster deployment
- Audio and video development interview questions
- 我在字节跳动「修电影」
- Market trend report, technological innovation and market forecast of China's double sided flexible printed circuit board (FPC)
猜你喜欢
原生js实现全选和反选的功能 --冯浩的博客
两个礼拜速成软考中级软件设计师经验
Codeforces round 797 (Div. 3) no f
第2章 HFDS的Shell操作
QT simulates mouse events and realizes clicking, double clicking, moving and dragging
Chapter 6 rebalance details
第6章 DataNode
Basic principles of video compression coding and audio compression coding
Solve the problem of intel12 generation core CPU [small core full, large core onlookers] (win11)
Chapter 6 datanode
随机推荐
两个礼拜速成软考中级软件设计师经验
Research Report on market supply and demand and strategy of Chinese table lamp industry
图像处理一百题(11-20)
Chapter 7__ consumer_ offsets topic
JS encapsulates the method of array inversion -- Feng Hao's blog
拉取分支失败,fatal: ‘origin/xxx‘ is not a commit and a branch ‘xxx‘ cannot be created from it
Double specific tyrosine phosphorylation regulated kinase 1A Industry Research Report - market status analysis and development prospect prediction
Study notes of Tutu - process
QT implementation window gradually disappears qpropertyanimation+ progress bar
LeetCode 1984. Minimum difference in student scores
Hbuilder X格式化快捷键设置
Educational Codeforces Round 122 (Rated for Div. 2)
SQL快速入门
Codeforces Round #802(Div. 2)A~D
Research Report of desktop clinical chemical analyzer industry - market status analysis and development prospect prediction
Chapter 5 yarn resource scheduler
Codeforces Global Round 19
第7章 __consumer_offsets topic
875. Leetcode, a banana lover
Installation and configuration of MariaDB