70-climbing-stairs

DevGod
Vtuber
int climbStairs(int n) { if(n <= 3){return n;} return climbStairs(n-1)+climbStairs(n-2);}
/** * @param {number} n * @return {number} */
var memo = {};var climbStairs = function(n) { if(n <= 3){return n;} if(memo[n-1] === undefined){ memo[n-1] = climbStairs(n-1); } if(memo[n-2] === undefined){ memo[n-2] = climbStairs(n-2); } return memo[n-1]+memo[n-2];}
class Solution { private array $memo = [0,1,2,3]; function climbStairs($n) { if($n <= 3){return $n;}
if($this->$memo[$n] == NULL){ $this->$memo[$n] = $this->climbStairs($n-1)+$this->climbStairs($n-2); }
return $this->$memo[$n]; }}
##int climbStairs(int n) { ## if(n <= 3){return n;} ## return climbStairs(n-1)+climbStairs(n-2);##}class Solution: @cache def climbStairs(self, n: int) -> int: if n <= 3: return n return self.climbStairs(n-1)+self.climbStairs(n-2)