上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 15 下一页
摘要: Given acompletebinary tree, count the number of nodes.Definition of a complete binary tree fromWikipedia:In a complete binary tree every level, except... 阅读全文
posted @ 2015-06-22 08:32 朱传林 阅读(147) 评论(0) 推荐(0) 编辑
摘要: Given preorder and inorder (Inorder and Postorder) traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in ... 阅读全文
posted @ 2015-06-22 08:26 朱传林 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 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 朱传林 阅读(104) 评论(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 朱传林 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 1、几乎所有关于二叉树的问题都可以用递归解决,二叉树和递归可谓相依相生;2、对于二叉树问题,递归的代码量往往比循环要简单很多,但简单不一定意味着好,递归的深度如果太大,容易引起栈溢出;3、遍历二叉树时,可以考虑使用栈存储二叉树;4、只要知道二叉树的前序和中序或后序和中序就可以还原二叉树,但前序和后序... 阅读全文
posted @ 2015-06-21 12:00 朱传林 阅读(100) 评论(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 朱传林 阅读(149) 评论(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 朱传林 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 三种方法中,递归最为简单,栈次之,循环最为麻烦。递归的深度如果太大则会导致栈溢出;栈的方式需要额外的辅助空间;循环编程最麻烦。 首先是递归://递归方法void midPrint_r(TreeNode* root){//中序遍历 if(root==NULL) return; if... 阅读全文
posted @ 2015-06-21 09:47 朱传林 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2015-06-18 16:44 朱传林 阅读(111) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... 阅读全文
posted @ 2015-06-18 15:48 朱传林 阅读(107) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 15 下一页