Q15 Catalan Number
Wed Mar 22 2023 16:52:18 GMT+0000 (Coordinated Universal Time)
Saved by
@Ayush_dabas07
// // "static void main" must be defined in a public class.
public class Main {
public static void main(String[] args) {
System.out.println(findCatalan(8));
}
//Function to find the nth catalan number.
public static int findCatalan(int n)
{
int dp[] = new int[n+1];
dp[0] = 1 ; dp[1] = 1;
for(int k = 2 ; k <= n; k++){
for(int i = 0 , j = k-1 ; i <= k-1 ; i++ , j--){
dp[k] += dp[i]*dp[j];
}
}
return dp[n];
}
}
content_copyCOPY
https://leetcode.com/playground/new/empty
Comments