摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le... 阅读全文
posted @ 2015-06-21 16:05 朱传林 阅读(111) 评论(0) 推荐(0)
摘要: Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
posted @ 2015-06-21 15:04 朱传林 阅读(123) 评论(0) 推荐(0)
摘要: 1、几乎所有关于二叉树的问题都可以用递归解决,二叉树和递归可谓相依相生;2、对于二叉树问题,递归的代码量往往比循环要简单很多,但简单不一定意味着好,递归的深度如果太大,容易引起栈溢出;3、遍历二叉树时,可以考虑使用栈存储二叉树;4、只要知道二叉树的前序和中序或后序和中序就可以还原二叉树,但前序和后序... 阅读全文
posted @ 2015-06-21 12:00 朱传林 阅读(104) 评论(0) 推荐(0)
摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文
posted @ 2015-06-21 11:49 朱传林 阅读(153) 评论(0) 推荐(0)
摘要: 反转二叉树:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :... 阅读全文
posted @ 2015-06-21 11:48 朱传林 阅读(164) 评论(0) 推荐(0)
摘要: 三种方法中,递归最为简单,栈次之,循环最为麻烦。递归的深度如果太大则会导致栈溢出;栈的方式需要额外的辅助空间;循环编程最麻烦。 首先是递归://递归方法void midPrint_r(TreeNode* root){//中序遍历 if(root==NULL) return; if... 阅读全文
posted @ 2015-06-21 09:47 朱传林 阅读(204) 评论(0) 推荐(0)