2274. Maximum Floors Without Special Floors
Question
Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only.
You are given two integers
bottom
andtop
, which denote that Alice has rented all the floors frombottom
totop
(inclusive). You are also given the integer arrayspecial
, wherespecial[i]
denotes a special floor that Alice has designated for relaxation.Return the maximum number of consecutive floors without a special floor.
Solution
可以视为特殊的动态规划。
计算每个特殊房间与上一个特殊房间的层数。(可以将底层的上一个房间视为特殊房间,需要将第一个房间设置为bottom-1)。
当距离大于当前结果时则更新res。
最后需要计算最后一层到上一个特殊房间的距离。(可以将顶楼的上一层视为特殊房间,因此直接计算top - lastRoom的层数即可)
Code
1 | class Solution { |
2274. Maximum Floors Without Special Floors
https://xuanhe95.github.io/2022/05/15/2274-Maximum-Floors-Without-Special-Floors/