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-07-23 13:47:56
阅读次数:
90
枚举每个长度为k的区间, 然后用平衡树找中位数进行判断, 时间复杂度O(nlogn).早上起来精神状态不太好...连平衡树都不太会写了...果断去看了会儿番然后就A了哈哈哈----------------------------------------------------------------...
分类:
其他好文 时间:
2015-07-23 13:30:08
阅读次数:
119
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.
直观地一想,查找第k小的数,不就是...
分类:
其他好文 时间:
2015-07-22 16:22:04
阅读次数:
87
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for a binary tree node. * public cla...
分类:
其他好文 时间:
2015-07-21 23:53:37
阅读次数:
176
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. ...
分类:
其他好文 时间:
2015-07-21 23:47:06
阅读次数:
145
题目:
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...
分类:
编程语言 时间:
2015-07-20 23:48:33
阅读次数:
209
题目:
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 straight forward. Could ...
分类:
编程语言 时间:
2015-07-20 23:47:29
阅读次数:
169
题目:
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.
...
分类:
编程语言 时间:
2015-07-20 14:36:18
阅读次数:
128
二叉查找树(Binary Search Tree,BST),(又:二叉搜索树,二叉排序树)它或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 它的左、右子树也分别为二叉排序树。...
分类:
编程语言 时间:
2015-07-19 19:27:00
阅读次数:
154
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:What if the BST is modifi...
分类:
其他好文 时间:
2015-07-19 16:32:18
阅读次数:
137