class Solution {
public:
int maxConsecutive(int bottom, int top, vector<int>& special) {
int ans = 0;
// 先排序
sort(begin(special), end(special));
// 方便后面计算
int lastLayer = bottom - 1;
int num = 0;
for(int i = 0; i < special.size(); i++){
num = special[i] - lastLayer;
ans = max(num, ans);
lastLayer = special[i];
}
ans--;
// 获取最后层数
num = top - lastLayer;
ans = max(ans, num);
return ans;
}
};
2274. 不含特殊楼层的最大连续楼层数
最新推荐文章于 2024-07-19 19:25:43 发布