package com.matao;

/**
 * Created by matao on 2018-12-07.
 */
public class Q10_Fibonacci {
}

@@ -17,78 +17,852 @@
 o;%0A%0A
-/**%0A * Created by matao on 2018-12-07.%0A */%0Apublic class Q10_Fibonacci %7B
+import com.matao.common.InvalidParameterException;%0A%0A/**%0A * Created by matao on 2018-12-07.%0A * %3Cp%3E%0A * %E6%B1%82%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97%E7%9A%84%E7%AC%AC n %E9%A1%B9%E7%9A%84%E5%80%BC%E3%80%82%0A * f(0) = 0%0A * f(1) = 1%0A * f(n) = f(n-1) + f(n-2), n %3E 1%0A */%0Apublic class Q10_Fibonacci %7B%0A%0A    public int fibRecursion(int n) %7B%0A        if (n %3C 0) %7B%0A            throw new InvalidParameterException(%22n must be greater than zero%22);%0A        %7D%0A%0A        if (n == 0 %7C%7C n == 1) return n;%0A        return fibRecursion(n - 1) + fibRecursion(n - 2);%0A    %7D%0A%0A    public int fibIteration(int n) %7B%0A        if (n %3C 0) %7B%0A            throw new InvalidParameterException(%22n must be greater than zero%22);%0A        %7D%0A%0A        if (n == 0 %7C%7C n == 1) return n;%0A%0A        int a = 0, b = 1;%0A        int i = 2;%0A        while (i %3C= n) %7B%0A            int temp = a + b;%0A            a = b;%0A            b = temp;%0A%0A            i++;%0A        %7D%0A        return b;%0A    %7D
 %0A%7D%0A

add Q10 Fibonacci