Skip to content

Commit 9d4d63b

Browse files
committed
feat: add typescript solution to lc problem: No.2274
No.2274.Maximum Consecutive Floors Without Special Floors
1 parent 97d71b9 commit 9d4d63b

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ class Solution {
8585
### **TypeScript**
8686

8787
```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+
};
8999
```
90100

91101
### **...**

solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README_EN.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,17 @@ class Solution {
7575
### **TypeScript**
7676

7777
```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+
};
7989
```
8090

8191
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
};

0 commit comments

Comments
 (0)