网页学习体会

  • 首页
  • 个人博客
您的位置: 首页  >  IT文章  >  Unique Binary Search Trees

Unique Binary Search Trees

分类: IT文章 • 2025-01-08 15:51:13

Given n, how many structurally unique BST's (binary search trees) that store values 1...n?

For example,
Given n = 3, there are a total of 5 unique BST's.

   1         3     3      2      1
           /     /      /       
     3     2     1      1   3      2
    /     /                        
   2     1         2                 3

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

相关推荐

  • 617. Merge Two Binary Trees
  • LeetCode T98.Validate Binary Search Tree/验证二叉搜索树
  • Unique Binary Search Trees @leetcode
  • leetcode[99]Recover Binary Search Tree
  • leetcode[108]Convert Sorted Array to Binary Search Tree
  • 树-二叉查找树 二叉查找树,二叉搜索树,Binary Search Tree 二叉查找树性质:左孩子<双亲<右孩子 二叉查找树插入与删除 二叉查找树实现
  • UVA1264 && UVAlive4847 Binary Search Tree
  • [Leetcode] DP-- 95. Unique Binary Search Trees II
  • Leetcode 之 Lowest Common Ancestor of a Binary Search Tree
  • 04-树6 Complete Binary Search Tree
  • windows下端口映射(端口转发) windows下端口映射(端口转发) 一.搞清楚概念 二.实现
  • jQuery函数的等价原生函数【转载】
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 网页学习体会    备案号:   粤ICP备20002247号