Leetcode / 70. Climbing Stairs
Pick a programming language:
Here is the source code for the solution to this problem.
class Solution {
public int climbStairs(int n) {
int prev = 1;
int curr = 1;
for (int i = 1; i < n; i++)
{
int temp = curr;
curr = curr + prev;
prev = temp;
}
return curr;
}
}
Did you like the lesson? 😆👍
Consider a donation to support our work: