【Leetcode】509. 斐波那契数列(Fibonacci Number)

Leetcode - 509 Fibonacci Number (Easy)

public int fib(int N) {
    if (N <= 1) return N;
    int a = 0, b = 1;
    while (N-- >= 2) {
        int tmp = b;
        b = a + b;
        a = tmp;
    }
    return b;
}

你可能感兴趣的:(LeetCode,数组,Leetcode,数组)