摘要: 原题地址:http://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/题意:Given a binary tree, flatten it to a linked list in-place.For example,Given... 阅读全文
posted @ 2014-05-10 22:55 南郭子綦 阅读(3779) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/binary-tree-postorder-traversal/题意:实现后序遍历。递归实现比较简单,非递归实现。解题思路:这道题的迭代求解比先序遍历和后序遍历要麻烦一些。假设一棵树是这样的: ... 阅读全文
posted @ 2014-05-10 18:40 南郭子綦 阅读(3270) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/binary-tree-preorder-traversal/题意:这题用递归比较简单。应该考察的是使用非递归实现二叉树的先序遍历。先序遍历的遍历顺序是:根,左子树,右子树。解题思路:如果树为下图: ... 阅读全文
posted @ 2014-05-10 12:44 南郭子綦 阅读(4203) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/binary-tree-inorder-traversal/题意:二叉树的中序遍历。这道题用递归比较简单,考察的是非递归实现二叉树中序遍历。中序遍历顺序为:左子树,根,右子树。如此递归下去。解题思路:假设树为: ... 阅读全文
posted @ 2014-05-10 11:50 南郭子綦 阅读(4859) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/balanced-binary-tree/题意:判断一颗二叉树是否是平衡二叉树。解题思路:在这道题里,平衡二叉树的定义是二叉树的任意节点的两颗子树之间的高度差小于等于1。这实际上是AVL树的定义。首先要写一个计算二叉树高度的函... 阅读全文
posted @ 2014-05-10 10:54 南郭子綦 阅读(5726) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/题意:根据二叉树的先序遍历和中序遍历恢复二叉树。解题思路:可以参照http://www.cnblogs.com... 阅读全文
posted @ 2014-05-10 10:40 南郭子綦 阅读(2234) 评论(1) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/题意:根据二叉树的中序遍历和后序遍历恢复二叉树。解题思路:看到树首先想到要用递归来解题。以这道题为例:如果一... 阅读全文
posted @ 2014-05-10 10:34 南郭子綦 阅读(3099) 评论(2) 推荐(0) 编辑