Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Climbing Stairs Problem (JS)

var climbStairs = function(n) {
    if (n == 1 || n == 0) return 1 // our base cases

    let first = 1;
    let second = 2;

    for (let i = 3; i <= n; i++) {
        let third = first + second;
        first = second;
        second = third;
    }
    return second;

};
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #Climbing #Stairs #Problem
ADD COMMENT
Topic
Name
5+8 =