LC2274. 不含特殊楼层的最大连续楼层数

题目链接:2274. 不含特殊楼层的最大连续楼层数 - 力扣(LeetCode)

题解

  • 排序,计算相邻元素差的最大值

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#
# @lc app=leetcode.cn id=2274 lang=python3
#
# [2274] 不含特殊楼层的最大连续楼层数
#

# @lc code=start
class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:

special.sort()
ans = special[0] - bottom if len(special) > 0 else top-bottom+1
for i in range(1, len(special)):
ans = max(ans, special[i] - special[i-1] - 1)
ans = max(ans, top-special[-1] if len(special) > 0 else top-bottom+1)
return ans

# @lc code=end

LC2274. 不含特殊楼层的最大连续楼层数

https://blog.xiang578.com/problem/lc2274.html

作者

Ryen Xiang

发布于

2025-01-12

更新于

2025-01-12

许可协议


网络回响

评论