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. Hearthstone-Deck-Tracker项目的编译

    https://github.com/HearthSim/Hearthstone-Deck-Tracker https://github.com/HearthSim/HearthDb https:// ...

  2. 如何在PADS的封装中做非金属化孔

    在设置封装的pads stacks的页面里,diameter,drill,plated三个项目(盘外径60mil,孔30mil) diameter:60,drill:30,plated:checked ...

  3. python strip()函数

    转发:jihite-博客园-python strip()函数 函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm)        删除s字符串中开头.结尾处,位于 rm删除序列的 ...

  4. 优秀的Markdown编辑器MarkdownPad2免费版使用全功能

    MarkdownPad,一款不错的Markdown编辑器,本人一直在用,具备所有Markdown的基本语法外支持一些特别的扩展,比如表格等. MarkdownPad分为免费版和收费版,区别是免费版不支 ...

  5. hdu 1116 Play on Words 欧拉路径+并查集

    Play on Words Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  6. Android Fast ImageLoader

    前段时间写的Android平台开源项目:Fast ImageLoader,现在分享给大家 源码地址:https://github.com/cumtkangyi/Android-Fast-ImageLo ...

  7. CISCO VPN出现网关报错

    今天尝试使用发现报错: 重启VPN服务即可

  8. iOS - Swift NSTimeZone 时区

    前言 public class NSTimeZone : NSObject, NSCopying, NSSecureCoding NSTimeZone 表示时区信息. 1.NSTimeZone 时区的 ...

  9. 十种JAVA排序算法实例

    一.冒泡(Bubble)排序 复制代码 代码如下: void BubbleSortArray() {       for(int i=1;i<n;i++)       {         for ...

  10. GCC编译器和GDB调试器常用选项

    http://blog.csdn.net/u014328976/article/details/46745349 GCC编译器 gcc hello.c -o hello                 ...