public int climbStairs(int n) {
if (n <= 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
int prevPrev = 1;
int prev = 2;
int curr = 0;
for (int i = 3; i <= n; i++) {
curr = prev + prevPrev;
prevPrev = prev;
prev = curr;
}
return curr;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-1035.html