注:本节主要讨论最大堆(最小堆同理)。一、堆的概念 堆,又称二叉堆。同二叉查找树一样,堆也有两个性质,即结构性和堆序性。 1、结构性质: 堆是一棵被完全填满的二叉树,有可能的例外是在底层,底层上的元素从左到右填入。这样的树称为完全二叉树(complete binary tree)。下图就是这样一个例...
分类:
其他好文 时间:
2014-11-28 15:49:09
阅读次数:
238
给定一个树,按照Z字形记录每一行。例如:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its zigzag level order traversal as:[ [3], [20,9], ...
分类:
其他好文 时间:
2014-11-28 14:18:16
阅读次数:
131
一,Xcode编译出现Link错误,出现"duplicate symbols for architecture i386 clang"提示. 问题:链接时,项目有重名文件. 解决: 根据错误提示,做如下检查: 1.Taraget->Build Settings->Link Binary With Libraries检查...
分类:
其他好文 时间:
2014-11-28 10:32:38
阅读次数:
193
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
这个题目比较简单,借助容器queue即可完成二叉树的层序遍历。我的C++实现代码如下:
vector > levelOrder(TreeNode *...
分类:
其他好文 时间:
2014-11-28 10:22:22
阅读次数:
206
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
这个简单的问题可以这样解决:利用LeetCode[Tree]: Binary Tree Level...
分类:
其他好文 时间:
2014-11-28 10:15:15
阅读次数:
227
给定一个数,广度优先输出记录。例如:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its level order traversal as:[ [3], [9,20], [15,7]]思...
分类:
其他好文 时间:
2014-11-28 01:04:56
阅读次数:
250
Source Insight不仅仅是一个强大的程序编辑器,它还能显示reference trees,class inheritance diagrams和call trees。Source Insight提供了最快速的对源代码的导航和任何程序编辑器的源信息。
但是美中不足的是在打开很多文件后,没...
分类:
其他好文 时间:
2014-11-28 00:57:34
阅读次数:
418
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.找树的最大路径和 注意路径可以从任意点起始和结束。我发现我真的还挺擅长树的题目的,递归不难。就是因为有个...
分类:
其他好文 时间:
2014-11-27 23:24:02
阅读次数:
284
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.有序数组变二叉平衡搜索树,不难,递归就行。每次先序建立根节点(取最中间的数),然后用子区间划分左右子树。一...
分类:
其他好文 时间:
2014-11-27 23:20:29
阅读次数:
269
Full Binary Tree
Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
In computer science, a binary tree is a tree data structure in which each node has at most two children...
分类:
其他好文 时间:
2014-11-27 20:34:56
阅读次数:
192