爬楼梯

const climbStairsFullStack = (n) => {
  if (n <= 2) {
    return n;
  }
  return climbStairsFullStack(n - 1) + climbStairsFullStack(n - 2);
};

const climbStairs = (n = 10) => {
  const map = new Map();
  const run = (n) => {
    if (n <= 2) return n;
    if (map.has(n)) return map.get(n);
    map.set(n, run(n - 1) + run(n - 2));
    return map.get(n);
  };
  return run(n);
};

  

posted @ 2020-08-18 20:04  671_MrSix  阅读(88)  评论(0编辑  收藏  举报