0
点赞
收藏
分享

微信扫一扫

LeetCode:96. 不同的二叉搜索树

兽怪海北 2022-04-26 阅读 23
javaleetcode

问题描述(原题链接)

代码:

class Solution {
    public int numTrees(int n) {
        //dp
        int[] dp = new int[n+1];
        dp[0]=1;
        dp[1]=1;
        for(int i=2;i<=n;i++){
            for(int j=1;j<=i;j++)
            dp[i]+=dp[j-1]*dp[i-j];
        }
        return dp[n];
    }
}
举报

相关推荐

0 条评论