The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n &gt; 1.


Given n, calculate F(n).

&nbsp;
Example 1:

Input: n = 2
Output: 1
Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.


Example 2:

Input: n = 3
Output: 2
Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.


Example 3:

Input: n = 4
Output: 3
Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.


&nbsp;
Constraints:


	0 &lt;= n &lt;= 30


class Solution:
    def fib(self, n: int) -> int:
        fa = [0, 1]

        for i in range(2, n + 1):
            fa.append(fa[i-2] + fa[i-1])

        return fa[n]
class Solution {
    public int fib(int n) {

        int[] fiboArray = new int[n+2];

        fiboArray[0] = 0;
        fiboArray[1] = 1;

        for(int i=2; i<=n; i++) {
            fiboArray[i] = fiboArray[i-1] + fiboArray[i-2];
        }

        return fiboArray[n];

    }
}
class Solution {
public:
    int fib(int n) {
        if(n<=1) return n;
        return fib(n-1)+fib(n-2);
    }
};
/**
 * @param {number} n
 * @return {number}
 */
 // Recursion and memomization approach
var fib = function(n,cache ={}) {
    if (n <= 0) return 0
    if(n in cache) {
        return cache[n]
    }
    if(n == 1 || n == 2) {
        return 1;
    }
    cache[n] = fib(n-1,cache) + fib(n-2,cache)
    return cache[n]
};
//Tabulation approach
var fib = function(n) {
    const table = new Array(n + 1).fill(0);
    table[1] = 1;
    for(let i = 0;i<=n;i++) {
            table[i+1] += table[i];
            table[i+2] += table[i];
    }
    return table[n]
};
Fibonacci Number