看到网上每个人都说是用DP解法,其实不就是个最普通不过的iterative解法吗?为什
么大家都把这个叫DP解法??
网上最流行的解法:
public int climbStairs(int n) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
if (n==1) return 1;
if (n==2) return 2;
int f1 = 1;
int f2 = 2;
int fi = 0;
for(int i=3; i<=n; i++)
{
fi = f1 + f2;
f1 = f2;
f2 = fi;
}
return fi;
}