-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1637.py
More file actions
31 lines (26 loc) · 837 Bytes
/
1637.py
File metadata and controls
31 lines (26 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
文件名: PersonalLeetCode 1637.py
作者: Bolun Xu
创建日期: 2025/3/18
版本: 1.0
描述: 两点之间不包含任何点的最宽垂直区域。
时间复杂度: O(Nlogn)
空间复杂度: O(N)
"""
from typing import List
class Solution:
def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:
x_list = []
for value in points:
x_list.append(value[0])
x_list.sort()
ans = 0
for i in range(1, len(x_list) - 1):
ans = max(x_list[i] - x_list[i - 1], ans)
return ans
if __name__ == '__main__':
solution = Solution()
print(solution.maxWidthOfVerticalArea([[8, 7], [9, 9], [7, 4], [9, 7]]))
print(solution.maxWidthOfVerticalArea([[3, 1], [9, 0], [1, 0], [1, 4], [5, 3], [8, 8]]))