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

Summary: dynamic programming

     int numTrees(int n) {
vector<int> nums;
nums.push_back();
for(int i = ; i <= n; i ++) {
if(i == ){
nums.push_back();
}else if(i == ){
int num = i * nums[i - ];
nums.push_back(num);
}else if(i >= ){
int num = ;
for(int j = ; j <= i; j ++)
num += (nums[j - ] == ? : nums[j - ]) * (nums[i - j] == ? : nums[i - j]);
nums.push_back(num);
}
}
return nums[n];
}

Unique Binary Search Trees [LeetCode]的更多相关文章

  1. Unique Binary Search Trees leetcode java

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

  2. Unique Binary Search Trees——LeetCode

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

  3. [LeetCode] 96. Unique Binary Search Trees(给定一个数字n,有多少个唯一二叉搜索树) ☆☆☆

    [Leetcode] Unique binary search trees 唯一二叉搜索树 Unique Binary Search Trees leetcode java 描述 Given n, h ...

  4. [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树

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

  5. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

  6. LeetCode:Unique Binary Search Trees I II

    LeetCode:Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees ...

  7. 【一天一道LeetCode】#96. Unique Binary Search Trees

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given n ...

  8. [leetcode]95. Unique Binary Search Trees II给定节点形成不同BST的集合

    Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ...

  9. [LeetCode] 95. Unique Binary Search Trees II(给定一个数字n,返回所有二叉搜索树) ☆☆☆

    Unique Binary Search Trees II leetcode java [LeetCode]Unique Binary Search Trees II 异构二叉查找树II Unique ...

随机推荐

  1. Cheatsheet: 2014 12.01 ~ 12.31

    .NET Some Thoughts on the new .Net Introducing .NET Core Running ASP.NET on a Raspberry Pi with Mono ...

  2. bootstrp水平表单格式

    1:form里添加类 "form-horizontal" 2:把标签和表单控件(input 等)放在一个带有类名 "form-group"的div里 3:标签可 ...

  3. 软/硬链接指令:ln

    语法: ln  [选项]  原文件  目标文件 选项: -s 创建软连接(创建软链接时,若所在文件夹不一致,原文件要使用绝对路径) 硬链接特征: 1.拥有相同i节点和存储block块,可以看成是同一个 ...

  4. DB2常识

    1.DB2组件 appendixa. db2 database product and packaging informatin一节AESE: 高级企业服务器版(Advanced enterprise ...

  5. 加快Win7整体运行速度的12个小技巧

    在整体运行速度方面,微软Windows 7系统超越了它的前任Vista,拥有明显的提升;但是相比最新的Windows 8,似乎又有所不及,至少很少有Windows用户能够体会到15秒的开机速度.虽然如 ...

  6. DBCP、C3P0、Proxool 、 BoneCP开源连接池的比《转》

     简介   使用评价  项目主页  DBCP DBCP是一个依赖Jakarta commons-pool对象池机制的数据库连接池.DBCP可以直接的在应用程序用使用 可以设置最大和最小连接,连接等待时 ...

  7. spring DI原理

    什么是IOC? 也称依赖注入 当一个类,需要另一个类的时候,我们不需要再另一个类里进行创建 对象,spring容器会给我们自动的创建 IOC的实现? 通过一定的技术读取spring.xml文件信息,比 ...

  8. 自学EF一些小笔记

    一直在用DHhelper做MVC,感觉好山寨,也不怎么好用.决定开始学EF. 废话不多说开始记笔记..... EF就是把数据库表,存储过程,视图实例化,通过继承DbContext的一个类来操作数据实例 ...

  9. linux2.6内核compat_ioctl函数

    一.内核原型(linux2.6.28-7) long (*compat_ioctl)(struct tty_struct *tty, struct file * file,               ...

  10. 手动配置WCF宿主的.config文件遇到的几种错误

    今天尝试用控制台应用程序作为WCF宿主,遇到几个问题,这几个问题虽然都不难,但寻找解决方案相当费时费力,做记录. WCF标准的配置文件为: <system.serviceModel>    ...