public class Fibonacci {
public static void main(String[] args) {
for (int i = 1; i < 12; i++) {
System.out.printf("fibonacci(%d) = %d\n", i, fibonacci(i));
}
}
public static int fibonacci(int size) {
if(size == 1 || size == 2) {
return 1;
}
return fibonacci(size -1 ) + fibonacci(size - 2);
}
}
时间复杂度:O(2^n)