剑指Offer——跳台阶

1、题目描述

  一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。

2、代码实现(和斐波那契数列是一模一样的)

 1  public int JumpFloor(int target) {
 2          int result = 0;
 3         if (target == 1) {
 4             result = 1;
 5         }
 6         if (target == 2) {
 7             result = 2;
 8         }
 9         if (target >= 3) {
10             result = JumpFloor(target - 1) + JumpFloor(target - 2);
11         }
12         return result;
13     }
原文地址:https://www.cnblogs.com/BaoZiY/p/11168461.html