You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

488 B

递归相关

10- I. 斐波那契数列

class Solution {

    public int fib(int n) {
        if (n == 0 || n == 1) {
            return n;
        }
        int start = 0;
        int end = 1;
        int result = 0;
        for (int i = 2; i <= n; i++) {
            result = (start + end) % 1000000007;
            start = end;
            end = result;
        }
        return result;
    }
}