public class Solution { //公式:f(n)= f(n-1)+f(n-2); public int jumpFloor(int number) { if(number == 1){ return 1; } //a 初始值为1 int a = 1; //a 初始值为2 int b = 2; //临时变量 int c = 0; for (int i = 2; i < number; i++) { //用c 临时储存f(n-1)+f(n-2) c = a + b; //a 前一轮b的值 a = b; //b=存f(n-1)+f(n-2) b = c; } return b; } }