摘要: 问题描述Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the ... 阅读全文
posted @ 2015-07-17 18:34 Chapter 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 问题描述Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next po... 阅读全文
posted @ 2015-07-17 17:53 Chapter 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 问题描述Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.解决思路递归思路。中序遍历的过程中,第一个违反顺序的节点一定是错... 阅读全文
posted @ 2015-07-17 12:08 Chapter 阅读(261) 评论(0) 推荐(0) 编辑
摘要: 问题描述给定一棵BST和一个数K,找出BST中与K值最为接近的数。解决思路递归。返回当前节点和目标值的差值、左子树节点和目标值的差值以及右子树节点和目标值的差值中,最小的那个所对应节点值。程序public class FindClosestInBST { public TreeNode findCl... 阅读全文
posted @ 2015-07-17 11:34 Chapter 阅读(614) 评论(0) 推荐(0) 编辑