/** * 非递归斐波那契数列 * @param args */ public static int getFieibolaLie(int number) { int data = 0; int n = 1; int m = 1; if (number <= 0) { return -1; } if (number == 1 || number == 2) { return 1; } while (number >= 2) { data += n; n = m; m = data; number--; } return data; } /** * 递归斐波那契数列 * @param n * @return */ public static int getFeiboLa(int n) { if (n ==1 || n == 2) { return 1; } return getFeiboLa(n - 1) + getFeiboLa(n - 2); }
时间: 2024-12-01 17:23:58