题目: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...
分类:
其他好文 时间:
2014-05-23 12:20:50
阅读次数:
407
题目: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-05-23 11:31:51
阅读次数:
299
出题:输入一个已经升序排序的数组和一个数字;要求在数组中查找两个数,这两个数的和正好等于输入的那个数字,输出任意一对数字就可以,要求时间复杂度是O(n);分析:对于升序排序的数组{…i…j…k…m……},只有可能是i+m=j+k(j和k可能是同一个数),所以可以从两边往中间收缩而忽视其他交叉相加的情...
分类:
其他好文 时间:
2014-05-19 12:04:14
阅读次数:
357
出题:把二元查找树转变成排序的双向链表。输入一棵二元查找树,要求将该二元查找树按照中序转换成一个排序的双向链表,要求不能创建任何新的节点,只能调整指针的指向;分析:递归的思路,当前节点需要进行的处理,并使用递归调用和返回值将子问题链接起来;首先明白二元查找树的特性,变成有序双向链表后当前根节点的左节...
分类:
其他好文 时间:
2014-05-19 10:02:49
阅读次数:
381
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...
分类:
其他好文 时间:
2014-05-19 07:23:48
阅读次数:
357
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 ...
分类:
其他好文 时间:
2014-05-17 14:45:17
阅读次数:
290
Problem Description:
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 l...
分类:
其他好文 时间:
2014-05-15 11:22:21
阅读次数:
317
Pat1043代码
题目描述:
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:
The left subtree of a node contains only nodes with keys less than t...
分类:
其他好文 时间:
2014-05-15 05:09:59
阅读次数:
351
Unique Binary Search Trees, Given n, how many structurally unique BST's (binary search trees) that store values 1...n?...
分类:
其他好文 时间:
2014-05-15 02:32:11
阅读次数:
245
Pat1043代码题目描述:A Binary Search Tree (BST) is
recursively defined as a binary tree which has the following properties:The left
subtree of a node contain...
分类:
其他好文 时间:
2014-05-14 22:03:25
阅读次数:
487