码迷,mamicode.com
首页 >  
搜索关键字:bst    ( 4557个结果
Java for LeetCode 108 Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:首先要理解,什么叫做height balanced BST,然后就十分容易了,JAVA实现如下:...
分类:编程语言   时间:2015-05-23 19:58:52    阅读次数:146
Java for LeetCode 099 Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.解题思路:先中序遍历找到mistake,然后替换即可,JAVA实现如下:...
分类:编程语言   时间:2015-05-22 01:49:49    阅读次数:111
Java for LeetCode 098 Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n...
分类:编程语言   时间:2015-05-21 22:32:43    阅读次数:187
Java for LeetCode 096 Unique Binary Search Trees
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'...
分类:编程语言   时间:2015-05-21 19:25:29    阅读次数:159
Java for LeetCode 095 Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should return all...
分类:编程语言   时间:2015-05-21 19:11:26    阅读次数:141
【Leetcode】【Medium】Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:用一个有序数组,创建一个平衡二叉查找树。为确保平衡,需要满足两子树的高度差不大于1,可以通过设置...
分类:其他好文   时间:2015-05-21 06:37:05    阅读次数:123
(DP) bzoj 3769
膜拜popoqqq大爷ORZZZZZZZZZZZZZZZZZZZZZZZZZZZ题目大意:求深度为h,大小为n个BST的数量对1000000007取模的值令f[i][j]为大小为i,深度为j以下的BST的数量设根节点为k,那么两个儿子一定分别是两个BST有递推式f[i][j]=(1<=k<=i)Σf...
分类:其他好文   时间:2015-05-20 13:09:17    阅读次数:131
2 Sum in Binary Search Tree
Given a BST, find 2 nodes in it which sum to a given targethint:Inorder traversal + BST + 2 SUM* Time : O(N)* Space: O(lgN) 1 class TreeNode0 { 2 ...
分类:其他好文   时间:2015-05-20 13:03:34    阅读次数:188
【leetcode】Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 1 class Solution { 2 public: 3 int l...
分类:其他好文   时间:2015-05-17 18:38:05    阅读次数:87
【Validate Binary Search Tree】cpp
题目:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains onl...
分类:其他好文   时间:2015-05-16 20:21:48    阅读次数:91
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!