Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:取数组的中点为树的根,前半部分为左子树,后半部分为右子树。 1 class Solution { 2...
分类:
其他好文 时间:
2014-08-17 13:02:12
阅读次数:
210
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思路:使用两个指针分别以1、2的速度遍历链表,以定位出链表的中点,进而将链表分割成...
分类:
其他好文 时间:
2014-08-17 02:21:36
阅读次数:
246
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST....
分类:
其他好文 时间:
2014-08-16 12:19:20
阅读次数:
227
Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n)
space is pretty s...
分类:
其他好文 时间:
2014-08-15 19:39:39
阅读次数:
222
$a="111111111111111111111111111111111111";@b = $a =~ /\w{3}/g; print "@b\n";@c = unpack("(A3)*", $a);print "$c[7]\n"; for ($i=1;$i<=13;$i=$i+3){$b=sub...
分类:
其他好文 时间:
2014-08-11 20:53:42
阅读次数:
959
Problem Description:
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n)
space is pretty straigh...
分类:
其他好文 时间:
2014-08-08 21:22:36
阅读次数:
315
二叉查找树BST----java实现
1.二叉查找树简介
二叉查找树又名二叉搜索树和二叉排序树。性质如下:
在二叉查找树中:
(01) 若任意节点的左子树不空,则左子树上所有结点的值均小于它的根结点的值;
(02) 任意节点的右子树不空,则右子树上所有结点的值均大于它的根结点的值;
(03) 任意节点的左、右子树也分别为二叉查找树。
(04) 没有键值相等的节点(no dupl...
分类:
编程语言 时间:
2014-08-07 03:07:38
阅读次数:
418
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...
分类:
其他好文 时间:
2014-08-07 00:16:36
阅读次数:
276
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 nodes with keys less than the node's key.Th...
分类:
其他好文 时间:
2014-08-05 09:43:39
阅读次数:
191
题目:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space....
分类:
编程语言 时间:
2014-08-05 05:17:28
阅读次数:
265