• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
2014年9月16日
Leetcode Binary Tree Zigzag level Order Traversal
摘要: 参考这道题其实还是树的层序遍历Binary Tree Level Order Traversal。不过这里稍微做了一点变体。在Binary Tree Level Order Traversal中我们是维护了一个队列来完成遍历,而在这里为了使每次都倒序出来,我们很容易想到用栈的结构来完成这个操作。有一 阅读全文
posted @ 2014-09-16 14:17 neverlandly 阅读(387) 评论(0) 推荐(0)
Leetcode: Construct Binary Tree from Inorder and Postorder Traversal
摘要: Given inorder and postorder traversal of a tree, construct the binary tree.与Construct Binary Tree from Inorder and Preorder Traversal问题非常类似,唯一区别在于这一次确... 阅读全文
posted @ 2014-09-16 10:59 neverlandly 阅读(358) 评论(0) 推荐(0)
Leetcode: Construct Binary Tree from Preorder and Inorder Traversal
摘要: 难度:95,参考了网上的思路。这道题是树中比较有难度的题目,需要根据先序遍历和中序遍历来构造出树来。这道题看似毫无头绪,其实梳理一下还是有章可循的。下面我们就用一个例子来解释如何构造出树。假设树的先序遍历是12453687,中序遍历是42516837。这里最重要的一点就是先序遍历可以提供根的所在,而 阅读全文
posted @ 2014-09-16 10:33 neverlandly 阅读(496) 评论(0) 推荐(0)
Leetcode: Flatten Binary Tree to Linked List
摘要: 第二遍做法:不用ArrayList来wrap up previous node, 直接把previous node做成全局变量 第一遍做法:用递归来解决,维护先序遍历的前一个结点pre,然后每次把pre的左结点置空,右结点设为当前结点。这里需要注意的一个问题就是我们要先把左右子结点(Code Gan 阅读全文
posted @ 2014-09-16 04:24 neverlandly 阅读(491) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3