Day 54: buckle 70, climb stairs

Address: leetcode-cn.com/problems/cl…

In dynamic programming, each increment is one or two, so one can add up from the third layer.

var climbStairs = function(n) {
  let res = [];
  res[0] = 1;
  res[1] = 1;
  for(let i = 2; i <= n; i++)
  {
    res[i] = res[i - 1] + res[i - 2];
  }
  return res[n];
};
Copy the code

Execution time: 84 ms, beating 50.16% of all JavaScript commits

Memory consumption: 37.6 MB, beating 38.47% of all JavaScript commits