秒杀,斐波那契数列。而且,其实不用像我的答案那也开数组的,用几个变量存就行了。
public class Solution { public int climbStairs(int n) { // Start typing your Java solution below // DO NOT write main() function if (n == 0) return 0; if (n == 1) return 1; if (n == 2) return 2; int m[] = new int[n+1]; m[1] = 1; m[2] = 2; for (int i = 3; i <=n; i++) { m[i] = m[i-1] + m[i-2]; } return m[n]; } }