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...
分类:
其他好文 时间:
2015-08-09 12:38:18
阅读次数:
141
hdu 4006 的传送门->Problem DescriptionXiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because...
分类:
其他好文 时间:
2015-08-08 18:24:56
阅读次数:
101
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-08-08 17:49:17
阅读次数:
121
Find thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For exampl...
分类:
其他好文 时间:
2015-08-06 22:09:52
阅读次数:
120
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-08-05 19:57:54
阅读次数:
123
The Kth smallest element in a BST
分类:
其他好文 时间:
2015-08-04 09:25:26
阅读次数:
113
题目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 m...
分类:
其他好文 时间:
2015-08-03 14:50:03
阅读次数:
112
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
For example,
Given [3,2,1,5,6,4] and k = 2, return 5....
分类:
其他好文 时间:
2015-08-02 23:25:40
阅读次数:
111
Treap的入门题目,每个结点多维护一个size表示以它为根的子树的结点数,然后查kth的时候一层一层向下即可。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 struc...
分类:
其他好文 时间:
2015-08-02 11:41:10
阅读次数:
148
//用search计算左子树的节点个数,加上根节点本身若为k则输出,否则
//(1)若k大于目前个数,则k-左子树节点个数,再计算右子树
//(2)若k小于目前个数,则直接计算左子树
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;...
分类:
其他好文 时间:
2015-07-29 06:28:26
阅读次数:
117