Skip to content

70. Climbing Stairs

https://leetcode.com/problems/climbing-stairs/

js
/**
 * @param {number} n
 * @return {number}
 */
var climbStairs = function(n) {
  var prev = 0
  var current = 1

  for (let i = 0; i < n; i++) {
    current = prev + current
    prev = current - prev
  }

  return current
}
py
class Solution(object):

    def climbStairs(self, n):
        """
        :type n: int
        :rtype: int
        """
        prev, current = 0, 1
        for i in range(n):
            prev, current = current, prev + current
        return current