[second]Climbing Stairs
f(n) = f(n-1)+f(n-2) DP
int climbStairs(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(n<=2)
return n;
int a = 1,b = 2;
int cnt;
for(int i=3;i<=n;i++)
{
cnt = a+b;
a = b;
b = cnt;
}
return cnt;
}
浙公网安备 33010602011771号