Skip to content

Commit 075480f

Browse files
authored
feat: add typescript solution to lc problem: No.0746.Min Cost Climbing Stairs (doocs#503)
1 parent 23a2f51 commit 075480f

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

solution/0700-0799/0746.Min Cost Climbing Stairs/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ class Solution {
7777
}
7878
```
7979

80+
### **TypeScript**
81+
82+
```ts
83+
function minCostClimbingStairs(cost: number[]): number {
84+
let a = 0, b = 0;
85+
for (let i = 1; i < cost.length; ++i) {
86+
[a, b] = [b, Math.min(a + cost[i - 1], b + cost[i])];
87+
}
88+
return b;
89+
};
90+
```
91+
8092
### **C++**
8193

8294
```cpp

solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ class Solution {
6767
}
6868
```
6969

70+
### **TypeScript**
71+
72+
```ts
73+
function minCostClimbingStairs(cost: number[]): number {
74+
let a = 0, b = 0;
75+
for (let i = 1; i < cost.length; ++i) {
76+
[a, b] = [b, Math.min(a + cost[i - 1], b + cost[i])];
77+
}
78+
return b;
79+
};
80+
```
81+
7082
### **C++**
7183

7284
```cpp
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function minCostClimbingStairs(cost: number[]): number {
2+
let a = 0, b = 0;
3+
for (let i = 1; i < cost.length; ++i) {
4+
[a, b] = [b, Math.min(a + cost[i - 1], b + cost[i])];
5+
}
6+
return b;
7+
};

0 commit comments

Comments
 (0)