A typical recursion use: class Solution(object): max_size = 0 # return: isValid, minVal, maxVal, nodeCnt def go(self, root): if root.left is None and
分类:
其他好文 时间:
2016-02-12 15:09:18
阅读次数:
169
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? 1 class Solution { 2 public: 3 int numTrees(int n) { 4 int
分类:
其他好文 时间:
2016-02-12 15:09:01
阅读次数:
135
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'
分类:
其他好文 时间:
2016-02-08 17:27:08
阅读次数:
186
题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 思路: 找到数组的中间数据作为根节点,小于中间数据的数组来构造作为左子树,大于中间数据的数组来构
分类:
其他好文 时间:
2016-02-05 18:41:10
阅读次数:
141
You are given a binary tree (not necessarily BST) in which each node contains a value. Design an algorithm to print all paths which sum up to that val
分类:
其他好文 时间:
2016-02-04 12:29:30
阅读次数:
120
98. Validate Binary Search Tree 题目 分析:BST按照中序遍历之后所得到的序列是一个递增序列,因此可以按照这个思路,先中序遍历,保存好遍历的结果,然后在遍历一遍这个序列。判断其是否递增 代码如下: 1 /** 2 * Definition for a binary t
分类:
其他好文 时间:
2016-02-03 14:32:36
阅读次数:
187
题目: Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ B
分类:
其他好文 时间:
2016-01-29 16:05:13
阅读次数:
141
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia
分类:
其他好文 时间:
2016-01-29 15:48:10
阅读次数:
128
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n
分类:
其他好文 时间:
2016-01-29 00:17:27
阅读次数:
197
Using DFS to traverse the BST, when we look through the BST to a certain node, this node must have the following property to make sure the tree is a v
分类:
其他好文 时间:
2016-01-28 13:45:06
阅读次数:
152