Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Solution: 1 /**...
分类:
其他好文 时间:
2014-11-29 01:31:14
阅读次数:
256
描述Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For ...
分类:
其他好文 时间:
2014-11-29 00:03:11
阅读次数:
442
返回树的深度。递归:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val...
分类:
其他好文 时间:
2014-11-28 16:06:24
阅读次数:
103
注:本节主要讨论最大堆(最小堆同理)。一、堆的概念 堆,又称二叉堆。同二叉查找树一样,堆也有两个性质,即结构性和堆序性。 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
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