Fastest Javascript solution


  • 0
    C
    var climbStairs = function(n) {
      if(n===1 || n===2) return n;
      var arr=[1,2];
      for(var i=2;i<n;i++){
        arr[i]=parseInt(arr[i-1])+parseInt(arr[i-2]);
      }
      return arr[n-1];}

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.