Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

nth catalan number

class Solution575
{
    static BigInteger[] catalan = new BigInteger[101];

    static{
        catalan[0] = new BigInteger("1");
        catalan[1] = new BigInteger("1");
    }

    //Function to find the nth catalan number.
    public static BigInteger findCatalan(int n)
    {
        //Your code here
        if(catalan[n]!=null){
            return catalan[n];
        }

        BigInteger total = new BigInteger("0");
        for(int i=0;i<n;i++){
            total = total.add(findCatalan(i).multiply(findCatalan(n-i-1)));
        }
        catalan[n] = total;
        return total;
    }
}
Source by practice.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #nth #catalan #number
ADD COMMENT
Topic
Name
3+3 =