通项公式解法:
public class Solution {
public int JumpFloor(int target) {
double k = 1.0/Math.sqrt(5);
double a = (1.0 + Math.sqrt(5))/2.0;
double b = (1.0 - Math.sqrt(5))/2.0;
int n = target + 1;
return (int)(k*(Math.pow(a, n) - Math.pow(b, n)));
}
}
京公网安备 11010502036488号