[Leetcode] Unique Binary Search Trees
来源:互联网 发布:沙发品牌推荐 知乎 编辑:程序博客网 时间:2024/05/16 14:40
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) { if(n <= 1) { return 1; } int[] cache = new int[n+1]; cache[0] = 1; cache[1] = 1; for(int j = 2; j <= n; j++) { for(int i = 0; i < j; i++) { cache[j] += cache[i]*cache[j-1-i]; } } return cache[n]; }}
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
- linux taskset命令详解
- 浏览器的内核分别是什么?经常遇到的浏览器兼容性有哪些
- HMTL符号手册
- Servlet 生命周期、工作原理
- linux LCD驱动
- [Leetcode] Unique Binary Search Trees
- 初识Spring-boot
- java练习--实现会员注册升级
- 牛人博客收集
- Conversion to Dalvik format failed with error 1
- webstrom
- 原生js实现双色球的方法
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- Spark的一些问题