forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClimbingStairs.js
More file actions
Latest commit
22 lines (19 loc) · 592 Bytes
/
Copy pathClimbingStairs.js
File metadata and controls
22 lines (19 loc) · 592 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* @function ClimbStairs
* @description You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
* @param {Integer} n - The input integer
* @return {Integer} distinct ways can you climb to the top.
* @see [Climb_Stairs](https://www.geeksforgeeks.org/count-ways-reach-nth-stair/)
*/
constclimbStairs=(n)=>{
letprev=0
letcur=1
lettemp
for(leti=0;i<n;i++){
temp=prev
prev=cur
cur+=temp
}
returncur
}
export{climbStairs}