Created
April 2, 2022 15:10
-
-
Save esase/36a2029d9ff3a0446541c93ca3f382d3 to your computer and use it in GitHub Desktop.
Climbing stairs [https://leetcode.com/problems/climbing-stairs]
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
/** | |
* @param {number} n | |
* @return {number} | |
*/ | |
var climbStairs = function(n) { | |
if (n === 1) { | |
return 1; | |
} | |
let first = 1; | |
let second = 1; | |
for (let i = n - 2; i >= 1; i--) { | |
let temp = first + second; | |
first = second; | |
second = temp; | |
} | |
return first + second; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment