LeetCode:Unique Binary Search Trees
来源:互联网 发布:淘宝大码女装 编辑:程序博客网 时间:2024/04/30 04:29
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
// Source : https://oj.leetcode.com/problems/unique-binary-search-trees/// Author : Chao Zeng// Date : 2014-12-18class Solution {public: int numTrees(int n) { return combination(2*n,n)/(n + 1); } int64_t combination(int num1, int num2){ int64_t ans1 = 1, ans2 = 1; int i; for (i = num1; i > num2; i--) ans1*=i; for (i = num2; i > 0; i--) ans2*=i; return ans1 / ans2; }};
0 0
- LeetCode: Unique Binary Search Trees
- LeetCode : Unique Binary Search Trees
- [Leetcode] Unique Binary Search Trees
- [LeetCode]Unique Binary Search Trees
- LeetCode Unique Binary Search Trees
- Leetcode: Unique Binary Search Trees
- LeetCode-Unique Binary Search Trees
- [leetcode] Unique Binary Search Trees
- LeetCode - Unique Binary Search Trees
- [LeetCode] Unique Binary Search Trees
- 【Leetcode】Unique Binary Search Trees
- Leetcode: Unique Binary Search Trees
- 【LeetCode】Unique Binary Search Trees
- Leetcode Unique Binary Search Trees
- Leetcode: Unique Binary Search Trees
- [LeetCode] Unique Binary Search Trees
- Leetcode: Unique Binary Search Trees
- LeetCode | Unique Binary Search Trees
- (OpenExplorer For Eclipse)Eclipse 中打开工程目录的插件
- 在引入的css或者js文件后面加参数的作用
- php抓取页面simple_html_dom的使用教程
- SQL语句中查找字符的位置
- Apache Shiro 使用手册(五)Shiro 配置说明
- LeetCode:Unique Binary Search Trees
- dubbo 分布式数据分离
- RGB配色表
- Eclipse 绑定 Android 源码。
- DIV+JS实现向上滚动百度新闻
- 在Ubuntu12.04.5_64bit上安装Ros Hydro
- 头文件中只能声明变量不能定义变量 而声明变量必须带extern,为什么头文件中变量的声明都没有加
- linux学习笔记:文件权限与目录配置
- asp.net web api使用默认路由 put delete动作在IIS下受限