Skip to content

Instantly share code, notes, and snippets.

@esase
Created April 2, 2022 15:10
Show Gist options
  • Save esase/36a2029d9ff3a0446541c93ca3f382d3 to your computer and use it in GitHub Desktop.
Save esase/36a2029d9ff3a0446541c93ca3f382d3 to your computer and use it in GitHub Desktop.
/**
* @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