https://leetcode.com/problems/climbing-stairs/description/
Solution 1.
int climbStairs(int n) {
if(n<=3) return n;
vector<int> ways(n,0);
ways[0] = 1;
ways[1] = 2;
ways[2] = 3;
for(int i=3;i<n;i++) {
ways[i] = ways[i-1] + ways[i-2];
}
return ways[n-1];
}
No comments:
Post a Comment