Skip to content

Commit 748bfc6

Browse files
committed
feat: add typescript solution to lc problem: No.2289
No.2289.Steps to Make Array Non-decreasing
1 parent 38e1fd2 commit 748bfc6

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

solution/2200-2299/2289.Steps to Make Array Non-decreasing/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,21 @@ func max(a, b int) int {
142142
### **TypeScript**
143143

144144
```ts
145-
145+
function totalSteps(nums: number[]): number {
146+
let ans = 0;
147+
let stack = [];
148+
for (let num of nums) {
149+
let max = 0;
150+
while (stack.length && stack[0][0] <= num) {
151+
max = Math.max(stack[0][1], max);
152+
stack.shift();
153+
}
154+
if (stack.length) max++;
155+
ans = Math.max(max, ans);
156+
stack.unshift([num, max]);
157+
}
158+
return ans;
159+
};
146160
```
147161

148162
### **...**

solution/2200-2299/2289.Steps to Make Array Non-decreasing/README_EN.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,21 @@ func max(a, b int) int {
130130
### **TypeScript**
131131

132132
```ts
133-
133+
function totalSteps(nums: number[]): number {
134+
let ans = 0;
135+
let stack = [];
136+
for (let num of nums) {
137+
let max = 0;
138+
while (stack.length && stack[0][0] <= num) {
139+
max = Math.max(stack[0][1], max);
140+
stack.shift();
141+
}
142+
if (stack.length) max++;
143+
ans = Math.max(max, ans);
144+
stack.unshift([num, max]);
145+
}
146+
return ans;
147+
};
134148
```
135149

136150
### **...**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function totalSteps(nums: number[]): number {
2+
let ans = 0;
3+
let stack = [];
4+
for (let num of nums) {
5+
let max = 0;
6+
while (stack.length && stack[0][0] <= num) {
7+
max = Math.max(stack[0][1], max);
8+
stack.shift();
9+
}
10+
if (stack.length) max++;
11+
ans = Math.max(max, ans);
12+
stack.unshift([num, max]);
13+
}
14+
return ans;
15+
};

0 commit comments

Comments
 (0)