题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.代码:oj测试通过Runtime:178 ms 1 # Definition...
分类:
编程语言 时间:
2015-01-11 20:18:51
阅读次数:
235
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....
分类:
其他好文 时间:
2015-01-11 14:46:32
阅读次数:
160
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.每次把中间元素当成根节...
分类:
其他好文 时间:
2015-01-11 12:10:19
阅读次数:
137
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
...
分类:
其他好文 时间:
2015-01-10 18:20:29
阅读次数:
181
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST....
分类:
其他好文 时间:
2015-01-09 22:29:55
阅读次数:
181
1. 概念:Binary-search tree(BST)是一颗二叉树,每个树上的节点都有parent.left.key。但找到x的parent就结束了吗,还没有,就像TREE-MINIMUM函数一样,我们需要逐层查找,当找到符合条件的parent后,我们递归的继续检查parent节点有没有pare...
分类:
编程语言 时间:
2015-01-09 20:48:25
阅读次数:
219
The problem:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(...
分类:
其他好文 时间:
2015-01-09 06:54:36
阅读次数:
132
The problem: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 con...
分类:
其他好文 时间:
2015-01-09 00:07:50
阅读次数:
208
QUESTIONImplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will retur...
分类:
其他好文 时间:
2015-01-08 23:57:45
阅读次数:
282
The problem:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.My analysis:The recursion is the best way...
分类:
其他好文 时间:
2015-01-08 00:49:30
阅读次数:
265