Skip to content

Commit 850e461

Browse files
authored
Create maximum-consecutive-floors-without-special-floors.cpp
1 parent cfe3d42 commit 850e461

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(nlogn)
2+
// Space: O(1)
3+
4+
// sort
5+
class Solution {
6+
public:
7+
int maxConsecutive(int bottom, int top, vector<int>& special) {
8+
sort(begin(special), end(special));
9+
int result = max(special[0] - bottom, top - special.back());
10+
for (int i = 1; i < size(special); ++i) {
11+
result = max(result, special[i] - special[i - 1] - 1);
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)