//递归 public static long recurFib(int num) { if (num < 2) { return num; } else { return recurFib(num - 1) + recurFib(num - 2); } } //动态规划 public static long dynFib(int num) { int[] nums = new int[num]; for (int i = 0; i < num; i++) { nums[i] = 0; } if (num == 1 || num == 2) { return 1; } else { nums[1] = 1; nums[2] = 2; for (int i = 3; i < num; i++) { nums[i] = nums[i - 1] + nums[i - 2]; } return nums[num - 1]; } }