/** * 双指针保存前面2个结果,不断更新。 * @param target * @return */ public static int jumpFloor(int target) { if (target == 0) return 0; if (target == 1) return 1; if (target == 2) return 2; int beforeBefore = 1; int before = 2; int cur = 3; for (int i = 3; i < target + 1; i++) { cur = before + beforeBefore; beforeBefore = before; before = cur; } return cur; }