-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abb6a9c
commit 9e5509c
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @param {number} n | ||
* @return {number} | ||
*/ | ||
var climbStairs = function(n) { | ||
let prev = 1 | ||
let step = 1 | ||
for (let i = 2; i < n + 1; i++) { | ||
let temp = step | ||
step = prev + step | ||
prev = temp | ||
} | ||
return step | ||
}; | ||
|
||
// 2022/07/06 done. | ||
// Runtime: 58 ms, faster than 96.04% of JavaScript online submissions for Climbing Stairs. | ||
// Memory Usage: 42.1 MB, less than 30.47% of JavaScript online submissions for Climbing Stairs. |