跳台阶
//时间复杂度O(2^n) 空间复杂度:递归栈的空间
public class Solution {
public int jumpFloor(int target) {
if(target==1)
return 1;
else if(target==2)
return 2;
else
return jumpFloor(target-1)+jumpFloor(target-2);
}
//时间复杂度O(n) 空间复杂度O(1)
public int jumpFloor(int target) {
int a = 1, b=1, c=1;
for(int i=2;i<=target;i++){
c = a+b;
a = b;
b = c;
}
return c;
}
}
本文来自博客园,作者:up~up,转载请注明原文链接:https://www.cnblogs.com/soft-engineer/p/15630848.html