Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4728ebf

Browse files
author
钱毓婷
committed
feat: add solution of Climbing Stairs(070) with javascript.
1 parent eaa2c1c commit 4728ebf

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
| [067][067-question] | [Add Binary][067-tips] | [Easy][E] | [][067-java] | [][067-js] | [][067-kotlin] |
7171
| [068][068-question] | [Text Justification][068-tips] | [Hard][H] | [][068-java] | | |
7272
| [069][069-question] | [Sqrt(x)][069-tips] | [Easy][E] | [][069-java] | [][069-js] | [][069-kotlin] |
73-
| [070][070-question] | [Climbing Stairs][070-tips] | [Easy][E] | [][070-java] | | [][070-kotlin] |
73+
| [070][070-question] | [Climbing Stairs][070-tips] | [Easy][E] | [][070-java] | [][070-js] | [][070-kotlin] |
7474
| [083][083-question] | [Remove Duplicates from Sorted List][083-tips] | [Easy][E] | [][083-java] | | [][083-kotlin] |
7575
| [088][088-question] | [Merge Sorted Array][088-tips] | [Easy][E] | [][088-java] | | [][088-kotlin] |
7676
| [100][100-question] | [Same Tree][100-tips] | [Easy][E] | [][100-java] | | [][100-kotlin] |
@@ -376,6 +376,7 @@
376376
[066-js]: ./src/_066/Solution.js
377377
[067-js]: ./src/_067/Solution.js
378378
[069-js]: ./src/_069/Solution.js
379+
[070-js]: ./src/_070/Solution.js
379380
[226-js]: ./src/_226/Solution.js
380381
[561-js]: ./src/_561/Solution.js
381382
[643-js]: ./src/_643/Solution.js

‎src/_070/Solution.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var climbStairs = function(n) {
6+
if(n == 1) {return 1}
7+
if(n == 2) {return 2}
8+
9+
var step1 = 1, step2 = 2, x;
10+
for(var i = 2 ; i < n; i++) {
11+
x = step2
12+
step2 += step1
13+
step1 = x
14+
}
15+
return step2
16+
};

‎tips/070/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ class Solution {
7373
}
7474
```
7575

76+
```JavaScript
77+
/**
78+
* @param {number} n
79+
* @return {number}
80+
*/
81+
var climbStairs = function(n) {
82+
if(n == 1) {return 1}
83+
if(n == 2) {return 2}
84+
85+
var step1 = 1, step2 = 2, x;
86+
for(var i = 2 ; i < n; i++) {
87+
x = step2
88+
step2 += step1
89+
step1 = x
90+
}
91+
return step2
92+
};
93+
```
7694
## 结语
7795

7896
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[LeetCode-Solution][ls]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /