File tree 3 files changed +33
-2
lines changed
solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,17 @@ class Solution {
85
85
### ** TypeScript**
86
86
87
87
``` ts
88
-
88
+ function maxConsecutive(bottom : number , top : number , special : number []): number {
89
+ let nums = special .slice ().sort ((a , b ) => a - b );
90
+ nums .unshift (bottom - 1 );
91
+ nums .push (top + 1 );
92
+ let ans = 0 ;
93
+ const n = nums .length ;
94
+ for (let i = 1 ; i < n ; i ++ ) {
95
+ ans = Math .max (ans , nums [i ] - nums [i - 1 ] - 1 );
96
+ }
97
+ return ans ;
98
+ };
89
99
```
90
100
91
101
### ** ...**
Original file line number Diff line number Diff line change @@ -75,7 +75,17 @@ class Solution {
75
75
### ** TypeScript**
76
76
77
77
``` ts
78
-
78
+ function maxConsecutive(bottom : number , top : number , special : number []): number {
79
+ let nums = special .slice ().sort ((a , b ) => a - b );
80
+ nums .unshift (bottom - 1 );
81
+ nums .push (top + 1 );
82
+ let ans = 0 ;
83
+ const n = nums .length ;
84
+ for (let i = 1 ; i < n ; i ++ ) {
85
+ ans = Math .max (ans , nums [i ] - nums [i - 1 ] - 1 );
86
+ }
87
+ return ans ;
88
+ };
79
89
```
80
90
81
91
### ** ...**
Original file line number Diff line number Diff line change
1
+ function maxConsecutive ( bottom : number , top : number , special : number [ ] ) : number {
2
+ let nums = special . slice ( ) . sort ( ( a , b ) => a - b ) ;
3
+ nums . unshift ( bottom - 1 ) ;
4
+ nums . push ( top + 1 ) ;
5
+ let ans = 0 ;
6
+ const n = nums . length ;
7
+ for ( let i = 1 ; i < n ; i ++ ) {
8
+ ans = Math . max ( ans , nums [ i ] - nums [ i - 1 ] - 1 ) ;
9
+ }
10
+ return ans ;
11
+ } ;
You can’t perform that action at this time.
0 commit comments