2014年(53)
发布时间:2014-12-13 18:20:56
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \ 4 8 .........【阅读全文】
发布时间:2014-12-13 17:52:36
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ .........【阅读全文】
发布时间:2014-12-06 18:21:44
需要牢记BST的定义:左边的所有节点都小于根节点,根节点小于右边的所有节点所以这样的做法是错误的:bool isValidBST(TreeNode *root) { if(root==NULL) return true; bool .........【阅读全文】
发布时间:2014-12-06 17:47:20
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 you devise a constant space solution?.........【阅读全文】
发布时间:2014-12-06 17:21:01
Given a binary tree, flatten it to a linked list in-place.这题直观的做法就是先序遍历,一个节点一个节点的塞到list里面,但是为了避免毁掉原本的链接,所以在递归中使用临时变量存储节点TreeNode * p=NULL;void f(TreeNode * root){ if(root==NULL).........【阅读全文】