当前位置:网站首页>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).
边栏推荐
- Summary of game theory
- Specify the format time, and fill in zero before the month and days
- Calculate the time difference
- 视频压缩编码和音频压缩编码基本原理
- 300th weekly match - leetcode
- Discussion on QWidget code setting style sheet
- Install Jupiter notebook under Anaconda
- Local visualization tools are connected to redis of Alibaba cloud CentOS server
- 我在字节跳动「修电影」
- QT implementation fillet window
猜你喜欢
Detailed explanation of FLV format
Browser print margin, default / borderless, full 1 page A4
Hbuilder x format shortcut key settings
Submit several problem records of spark application (sparklauncher with cluster deploy mode)
第5章 NameNode和SecondaryNameNode
< li> dot style list style type
Kubernetes cluster deployment
第五章 Yarn资源调度器
第7章 __consumer_offsets topic
Solve the problem that intel12 generation core CPU single thread only runs on small cores
随机推荐
Cmake Express
使用jq实现全选 反选 和全不选-冯浩的博客
Chapter 7__ consumer_ offsets topic
(lightoj - 1349) Aladdin and the optimal invitation (greed)
Chapter III principles of MapReduce framework
Spark独立集群Worker和Executor的概念
第6章 Rebalance详解
(lightoj - 1369) answering queries (thinking)
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Solve the single thread scheduling problem of intel12 generation core CPU (II)
Hbuilder X格式化快捷键设置
Codeforces Round #798 (Div. 2)A~D
Discussion on QWidget code setting style sheet
Submit several problem records of spark application (sparklauncher with cluster deploy mode)
MariaDB的安装与配置
视频压缩编码和音频压缩编码基本原理
Codeforces Round #800 (Div. 2)AC
第一章 MapReduce概述
Codeforces Round #801 (Div. 2)A~C
300th weekly match - leetcode