第一开始想着枚举根节点,然后记忆化搜索。。结果TLE,最后还是看了一眼题解瞬间明白了。。唉,还是思维太局限了由于数据是按照从小到大排列的,可以自然地组成一颗二叉排序树。设dp[i][j]是区间[i,j]的元素可以组成的BST的最小值,则大区间的结果和根节点以及小区间的结果有关系,很明显区间DP,转移...
分类:
其他好文 时间:
2015-09-23 10:08:38
阅读次数:
222
解题思路:直接修改中序遍历函数即可,JAVA实现如下:int res = 0; int k = 0; public int kthSmallest(TreeNode root, int k) { this.k = k; inorderTraversal(root); return res; }...
分类:
编程语言 时间:
2015-09-22 18:50:13
阅读次数:
130
Problem Description:Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in...
分类:
其他好文 时间:
2015-09-22 18:28:52
阅读次数:
171
Inorder Successor in BSTGiven a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has n...
分类:
其他好文 时间:
2015-09-22 16:04:13
阅读次数:
144
Problem:Given a non-empty binary search tree and a target value, findkvalues in the BST that are closest to the target.Note:Given target value is a fl...
分类:
其他好文 时间:
2015-09-20 11:48:20
阅读次数:
298
Question:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wi...
分类:
其他好文 时间:
2015-09-20 11:39:08
阅读次数:
175
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 ...
分类:
其他好文 时间:
2015-09-18 13:56:58
阅读次数:
178
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ...
分类:
其他好文 时间:
2015-09-17 06:20:37
阅读次数:
159
Binary Search Tree IteratorImplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callin...
分类:
其他好文 时间:
2015-09-16 23:20:13
阅读次数:
171
Elven PostmanTime Limit: 1500/1000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 147Accepted Submission(s): 90Proble...
分类:
其他好文 时间:
2015-09-13 21:33:39
阅读次数:
153