摘要: public class SortedMap { //treemap按key排序,默认是升序,可自定义降序 public static void main(String[] args) { Map map = new TreeMap(new Comparator() { public int compare(Integer a, Integer b) { ... 阅读全文
posted @ 2016-10-17 10:33 32ddd 阅读(323) 评论(0) 推荐(0) 编辑
摘要: 算法分析:求树的最小最大深度时候,都有两种方法,第一种是递归思想。树最大最小深度,即为它的子树的最大最小深度+1,是动态规划的思想。还有一种方法是层序遍历树,只不过求最小深度时,找到第一个叶子节点就可以返回,该节点的深度,即为树的最小深度。求最大深度时,需要层序遍历完整棵树。 阅读全文
posted @ 2016-09-27 02:04 32ddd 阅读(534) 评论(0) 推荐(0) 编辑
摘要: 算法分析:递归和非递归两种方法。 阅读全文
posted @ 2016-09-27 01:26 32ddd 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 第一种也是最常用的一种,使用queue。还有一种不使用queue的方法。不使用queue的思路,其实就是每次都只存储一层的节点,然后遍历这一层的节点,是真正的按层遍历的思想。每次遍历的都是当前层,记录的都是当前层的下一层。 阅读全文
posted @ 2016-09-27 00:40 32ddd 阅读(9380) 评论(0) 推荐(1) 编辑
摘要: 问题描述: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next leve 阅读全文
posted @ 2016-09-26 20:10 32ddd 阅读(861) 评论(0) 推荐(0) 编辑
摘要: 问题描述: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary t 阅读全文
posted @ 2016-09-26 17:47 32ddd 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 问题描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is 阅读全文
posted @ 2016-09-24 18:57 32ddd 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 算法分析:这道题很简单,利用递归即可。 阅读全文
posted @ 2016-09-03 16:34 32ddd 阅读(499) 评论(0) 推荐(0) 编辑
摘要: 问题描述:题意就是二叉树中有两个节点交换了,恢复结构。 Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. 算法分析:其 阅读全文
posted @ 2016-09-03 15:37 32ddd 阅读(300) 评论(0) 推荐(0) 编辑
摘要: 算法分析:两种方法,一种是中序遍历,然后得到一个序列,看序列是否是有序的。第二种,是用递归。 中序遍历: 递归: 阅读全文
posted @ 2016-09-02 22:10 32ddd 阅读(209) 评论(0) 推荐(0) 编辑