题目:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedi...
分类:
其他好文 时间:
2015-11-05 10:32:12
阅读次数:
134
题意: 寻找一棵BST中的第k小的数。思路: 递归比较方便。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * ...
分类:
其他好文 时间:
2015-11-04 21:04:21
阅读次数:
296
题目:
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 ≤ BST's total elements.
Follow up:
Wh...
分类:
其他好文 时间:
2015-10-30 10:52:12
阅读次数:
170
package cn.edu.xidian.sselab;/*** title:Lowest Common Ancestor of a Binary Search Tree* content:* Given a binary search tree (BST), * find the lowest ...
分类:
其他好文 时间:
2015-10-29 00:42:52
阅读次数:
215
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.首先是O(N)空间的方法,用递归: 1 /** 2 * Definit....
分类:
其他好文 时间:
2015-10-28 22:29:11
阅读次数:
240
Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1.....
分类:
其他好文 时间:
2015-10-27 13:15:16
阅读次数:
242
Use one queue + size variable 1 public class Solution { 2 public ArrayList> levelOrder(TreeNode root) { 3 ArrayList result = new ArrayList...
分类:
其他好文 时间:
2015-10-26 01:49:59
阅读次数:
300
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.讲一个排序好的数组转换成二叉搜索树,这题没想出来,基本上是参考别人的,边界条件应该注意一下: 1 /** ...
分类:
编程语言 时间:
2015-10-25 22:27:01
阅读次数:
272
Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota...
分类:
其他好文 时间:
2015-10-25 13:36:39
阅读次数:
131
CButton::SetCheck void SetCheck(int nCheck); 参数 nCheck 指定检查状态。 此参数可以是下列值之一: 值 含义 BST_UNCHECKED 将按钮状态为未选中状态。 BST_CHECKED ...
分类:
编程语言 时间:
2015-10-23 18:33:42
阅读次数:
256