【题目】
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
For example:
Given the following binary tre...
分类:
其他好文 时间:
2015-04-06 11:32:47
阅读次数:
173
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 5 unique BST's shown below.
1 3 ...
分类:
其他好文 时间:
2015-04-04 18:28:21
阅读次数:
116
treap,算是模板题了...我中间还一次交错题...--------------------------------------------------------------------#include#include#include#include#include#define rep(i,n...
分类:
其他好文 时间:
2015-04-04 18:07:21
阅读次数:
120
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-04-04 15:01:48
阅读次数:
117
题目:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
思路:从一个数组中找到中间的元素作为BST的根,然后坐边的作为左子树,右边的作为右子树,递归调用
#include
#include
#include
#include
...
分类:
其他好文 时间:
2015-04-04 12:18:29
阅读次数:
132
题目:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
思路:和上面的思想一样,只不过注意找到链表的中间节点的方法
void Inorder(BinTree* root)
{
if(root == NULL)
...
分类:
其他好文 时间:
2015-04-04 12:17:29
阅读次数:
136
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 ...
分类:
其他好文 时间:
2015-04-03 13:17:49
阅读次数:
120
二叉查找树是 左子节点 data = data; node->left = NULL; node->right = NULL; return node;}//定义一个函数用来删除某个节点void destroy(BST_Node* node){ free(node);}然后...
分类:
其他好文 时间:
2015-04-01 01:44:07
阅读次数:
149
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题解:递归就可以了。Java代码如下: 1 /** 2 * Definition for binary ....
分类:
其他好文 时间:
2015-04-01 00:16:07
阅读次数:
96
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
之前在Sicily做过,就是实现一个AVL树了。
struct TreeNodeNew {
int val;
TreeNodeNew *left;
Tr...
分类:
其他好文 时间:
2015-03-31 18:09:23
阅读次数:
150