ds-algo-study
Version:
Just experimenting with publishing a package
15 lines (11 loc) • 406 B
JavaScript
// Work through this problem on https://leetcode.com/problems/climbing-stairs/ and use the specs given there.
// Feel free to use this file for scratch work.
var climbStairs = function ( n ) {
let table = new Array( n + 1 ).fill( 0 );
table[ 0 ] = 1;
for ( let i = 0; i < n; i++ ) {
table[ i + 1 ] += table[ i ];
if ( i + 2 <= n ) table[ i + 2 ] += table[ i ];
}
return table[ n ];
};