binary search tree,中文翻译为二叉搜索树、二叉查找树或者二叉排序树。简称为BST。
本文集齐了二叉树的五大遍历算法:先序遍历、中序遍历、后序遍历、深度优先遍历和广度优先遍历(同层遍历也就是深度优先遍历)。
// BSTree.h
#include
#include
#include
#include
using namespace std;
// bin...
分类:
编程语言 时间:
2014-12-04 01:02:39
阅读次数:
303
Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3...
分类:
其他好文 时间:
2014-12-04 00:52:08
阅读次数:
191
给定一颗数,然后任意的起点或者终点,找到最大的路径和。例如:Given the below binary tree, 1 / \ 2 3Return6.一看到是标hard的题目就觉得要吃力才能搞出来。果然,经过不懈奋斗,成功从Time Limited到AC。我看到这...
分类:
其他好文 时间:
2014-12-04 00:42:49
阅读次数:
245
Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 ...
分类:
其他好文 时间:
2014-12-03 23:14:20
阅读次数:
163
isSameTree1Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally i...
分类:
其他好文 时间:
2014-12-03 23:11:24
阅读次数:
367
这是LeetCode上的一道题目,需要求二叉树中两点路径的最大和。原题是https://oj.leetcode.com/problems/binary-tree-maximum-path-sum/Given a binary tree, find the maximum path sum.The p...
分类:
其他好文 时间:
2014-12-03 23:05:58
阅读次数:
226
Symmetric TreeGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric...
分类:
其他好文 时间:
2014-12-03 23:00:53
阅读次数:
290
Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni...
分类:
其他好文 时间:
2014-12-03 22:46:11
阅读次数:
192
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.public class Solution { public...
分类:
其他好文 时间:
2014-12-03 22:43:28
阅读次数:
191
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
这类问题非常适合用递归做,递归思路如下:
前序遍历的第一个节点必然是根节点,中序遍历中根节点之前的节...
分类:
其他好文 时间:
2014-12-03 21:27:24
阅读次数:
172