Chinaunix首页 | 论坛 | 博客
  • 博客访问: 117271
  • 博文数量: 53
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 620
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-24 16:22
文章存档

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 .........【阅读全文】

阅读(1329) | 评论(0) | 转发(0)

发布时间: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 / \ .........【阅读全文】

阅读(1181) | 评论(0) | 转发(0)

发布时间:2014-12-06 18:21:44

需要牢记BST的定义:左边的所有节点都小于根节点,根节点小于右边的所有节点所以这样的做法是错误的:bool isValidBST(TreeNode *root) {    if(root==NULL)        return true;    bool .........【阅读全文】

阅读(1362) | 评论(0) | 转发(0)

发布时间: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?.........【阅读全文】

阅读(1107) | 评论(0) | 转发(0)

发布时间: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).........【阅读全文】

阅读(930) | 评论(0) | 转发(0)
给主人留下些什么吧!~~
留言热议
请登录后留言。

登录 注册