加载中...
1637-两点之间不包含任何点的最宽垂直面积(Widest Vertical Area Between Two Points Containing No Points)
发表于:2021-12-03 | 分类: 中等
字数统计: 339 | 阅读时长: 1分钟 | 阅读量:

原文链接: https://leetcode-cn.com/problems/widest-vertical-area-between-two-points-containing-no-points

英文原文

Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.

A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width.

Note that points on the edge of a vertical area are not considered included in the area.

 

Example 1:

Input: points = [[8,7],[9,9],[7,4],[9,7]]
Output: 1
Explanation: Both the red and the blue area are optimal.

Example 2:

Input: points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
Output: 3

 

Constraints:

  • n == points.length
  • 2 <= n <= 105
  • points[i].length == 2
  • 0 <= xi, yi <= 109

中文题目

给你 n 个二维平面上的点 points ,其中 points[i] = [xi, yi] ,请你返回两点之间内部不包含任何点的 最宽垂直面积 的宽度。

垂直面积 的定义是固定宽度,而 y 轴上无限延伸的一块区域(也就是高度为无穷大)。 最宽垂直面积 为宽度最大的一个垂直面积。

请注意,垂直区域 边上 的点 不在 区域内。

 

示例 1:

输入:points = [[8,7],[9,9],[7,4],[9,7]]
输出:1
解释:红色区域和蓝色区域都是最优区域。

示例 2:

输入:points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
输出:3

 

提示:

  • n == points.length
  • 2 <= n <= 105
  • points[i].length == 2
  • 0 <= xi, yi <= 109

通过代码

高赞题解

def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:
    points.sort(key=lambda p:p[0])
    return max(p2[0] - p1[0] for p1, p2 in zip(points, points[1:]))

统计信息

通过次数 提交次数 AC比率
5625 6965 80.8%

提交历史

提交时间 提交结果 执行时间 内存消耗 语言
上一篇:
1638-统计只差一个字符的子串数目(Count Substrings That Differ by One Character)
下一篇:
1639-通过给定词典构造目标字符串的方案数(Number of Ways to Form a Target String Given a Dictionary)
本文目录
本文目录