[LeetCode] Unqiue Binary Search Trees I
来源:互联网 发布:写composer php插件 编辑:程序博客网 时间:2024/04/27 15:11
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
相关问题:返回所有可能的BST。
思路:很简单,用递归。
int numTrees(int n) { if(n==0) return 1; if(n==1) return 1; int total = 0; for(int i=0; i<n; i++) { total = total+numTrees(i)*numTrees(n-i-1); } return total; }
0 0
- [LeetCode] Unqiue Binary Search Trees I
- [LeetCode] Unqiue Binary Search Trees II
- 【LeetCode】Unique Binary Search Trees I && II
- [Leetcode]Unique Binary Search Trees I & II
- (Leetcode)Unique Binary Search Trees I & II
- [LeetCode]Unique Binary Search Trees I&II
- leetcode -day28 Unique Binary Search Trees I II
- 【LeetCode从零单刷】Unique Binary Search Trees I & II
- leetcode -- Unique Binary Search Trees I&II -- 重点
- LeetCode 95, 96. Unique Binary Search Trees i. ii
- [LeetCode] 95. Unique Binary Search Trees II & I
- 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
- centos yum
- 图片加速技术
- 浅析Android权限机制(一) —— Android的权限机制
- MySQL和MongoDB设计实例对比
- HDFS源码解析(二)
- [LeetCode] Unqiue Binary Search Trees I
- nyoj 264 国王的魔镜
- 中国人都争着当"屌丝"?
- Selector选择器的使用
- 【Objective-C】04-OC对象成员变量的封装规范:get方法和set方法
- 使用Java在本地创建一个服务器 ,通过浏览器对其进行访问的一个简单测试
- mini2440 文件系统
- VS2010平台下ImageDib类开发----------------------二值化
- 如何用Vs2008打开Vs2010所建的项目