当前位置:网站首页>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).
边栏推荐
- Educational Codeforces Round 130 (Rated for Div. 2)A~C
- LeetCode 1551. Minimum operand to make all elements in the array equal
- One hundred questions of image processing (1-10)
- Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
- Codeforces - 1526C1&&C2 - Potions
- Discussion on QWidget code setting style sheet
- LeetCode 1984. Minimum difference in student scores
- 300th weekly match - leetcode
- Educational Codeforces Round 122 (Rated for Div. 2)
- Ffmpeg command line use
猜你喜欢
Chapter 5 detailed explanation of consumer groups
音视频开发面试题
本地可视化工具连接阿里云centOS服务器的redis
Raspberry pie 4B installation opencv3.4.0
LeetCode 1557. The minimum number of points that can reach all points
Log statistics (double pointer)
(lightoj - 1369) answering queries (thinking)
Solve the problem of intel12 generation core CPU [small core full, large core onlookers] (win11)
LeetCode 1560. The sector with the most passes on the circular track
软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
随机推荐
How to insert mathematical formulas in CSDN blog
Kubernetes cluster deployment
第5章 消费者组详解
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
China double brightening film (dbef) market trend report, technical dynamic innovation and market forecast
Study notes of Tutu - process
Mp4 format details
视频压缩编码和音频压缩编码基本原理
业务系统从Oracle迁移到openGauss数据库的简单记录
Problem - 1646C. Factorials and Powers of Two - Codeforces
Two weeks' experience of intermediate software designer in the crash soft exam
Kubernetes集群部署
Codeforces Round #771 (Div. 2)
Date plus 1 day
Base dice (dynamic programming + matrix fast power)
第一章 MapReduce概述
软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
Research Report on market supply and demand and strategy of China's four flat leadless (QFN) packaging industry
QT simulates mouse events and realizes clicking, double clicking, moving and dragging
Market trend report, technical innovation and market forecast of tabletop dishwashers in China