解题思路:有n个台阶时,F(n)=F(n-1)+F(n-2)+F(n-3)+……+F(1)+F(0).又因为F(1)=F(0)=1,经计算可得,F(n)=2^(n-1)
import java.lang.Math; public class Solution { public int JumpFloorII(int target) { if(target<2){ return 1; } return (int)Math.pow(2,target-1); } }
解题思路:有n个台阶时,F(n)=F(n-1)+F(n-2)+F(n-3)+……+F(1)+F(0).又因为F(1)=F(0)=1,经计算可得,F(n)=2^(n-1)
import java.lang.Math; public class Solution { public int JumpFloorII(int target) { if(target<2){ return 1; } return (int)Math.pow(2,target-1); } }