Skip to content

Commit ed2b469

Browse files
committed
solve: climbing stairs
1 parent 6f4e4dc commit ed2b469

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

climbing-stairs/wogha95.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// TC: O(N)
2+
// SC: O(1)
3+
4+
/**
5+
* @param {number} n
6+
* @return {number}
7+
*/
8+
var climbStairs = function (n) {
9+
let previousStep = 0;
10+
let currentStep = 1;
11+
12+
while (n > 0) {
13+
n -= 1;
14+
const nextStep = previousStep + currentStep;
15+
previousStep = currentStep;
16+
currentStep = nextStep;
17+
}
18+
19+
return currentStep;
20+
};

0 commit comments

Comments
 (0)