同样是层序遍历,在每次迭代中挑出最小的设置为已知,收敛 表初始化 显示实际路径 算法伪代码 ...
分类:
编程语言 时间:
2017-07-30 12:43:26
阅读次数:
193
【107-Binary Tree Level Order Traversal II(二叉树层序遍历II)】 【LeetCode-面试算法经典-Java实现】【全部题目文件夹索引】 原题 Given a binary tree, return the bottom-up level order tra ...
分类:
编程语言 时间:
2017-07-21 23:25:59
阅读次数:
226
非常easy的题目。只是还是认为要说一下。最小深度。非常快想到bfs,层序遍历嘛。本科的时候实在是没写过多少代码,一開始竟然想不到怎么保存一层的信息。后来想到能够压入一个特殊的对象,每次到达这个对象就知道是一层了。我用的是空指针。认为这个适用性还是不错的。一层的节点入队结束后,应该压入一个NULL。 ...
分类:
其他好文 时间:
2017-06-29 10:02:53
阅读次数:
120
题目描写叙述: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binar ...
分类:
其他好文 时间:
2017-06-25 22:09:58
阅读次数:
196
https://leetcode.com/problems/binary-tree-level-order-traversal-ii/#/solutions 这题跟层序遍历没有什么不同,只是把最后结果reverse 一下而已。不知道还有没有其他的套路? 可以分别用BFS 和DFS,后者要更简洁一点。 ...
分类:
其他好文 时间:
2017-06-17 14:20:15
阅读次数:
143
public class Tree<AnyType extends Comparable<? super AnyType>> { private static class BinaryNode<AnyType> {BinaryNode(AnyType theElement) { this(theEl ...
分类:
编程语言 时间:
2017-05-30 20:57:48
阅读次数:
263
DescriptionGiven a 2D grid, each cell is either a wall 2, a zombie 1 or people 0 (the number zero, one, two).Zombies can turn the nearest people(up/do ...
分类:
其他好文 时间:
2017-05-14 12:22:11
阅读次数:
357
一、树的遍历算法 树的创建 前序遍历 中序遍历 后序遍历 层序遍历 二、重建二叉树 问题描述:输入二叉树的前序与中序,输出重建的二叉树。 问题描述:输入二叉树的后序与中序,输出重建的二叉树。 ...
分类:
其他好文 时间:
2017-05-07 20:29:16
阅读次数:
200
private void LevelOrder(TreeNode node) { Queue queue = new Queue(); queue.Enqueue(node); TreeNode treeNode = null; while(queue.Count>0) { treeNode = q... ...
分类:
其他好文 时间:
2017-04-12 19:45:58
阅读次数:
188
二叉树遍历分为前序、中序、后序递归和非递归遍历、还有层序遍历。 ...
分类:
编程语言 时间:
2017-04-06 22:15:30
阅读次数:
260