二叉搜索树,也叫二叉排序树、二叉查找树或BST(Binary Search Tree)。二叉搜索树或是一棵空疏,或者是一棵具有下列特性的非空二叉树:1. 若左子树非空,则左子树上的所有节点的关键字值均小于根节点的关键字的值。2. 若右子树非空,则右子树上的所有节点的关键字值均大于根节点的关键字的值。...
分类:
其他好文 时间:
2015-01-12 22:29:06
阅读次数:
206
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 /...
分类:
移动开发 时间:
2015-01-12 22:25:01
阅读次数:
151
Follow up for "Find Minimum in Rotated Sorted Array":
What if duplicates are allowed?
Would this affect the run-time complexity? How and why?
Suppose a sorted array is rotated at some pivot u...
分类:
其他好文 时间:
2015-01-12 21:04:07
阅读次数:
224
题目:
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
For example:
Given the below binary tree and sum
= 22,
5
/...
分类:
编程语言 时间:
2015-01-12 19:24:15
阅读次数:
170
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100".
class Solution
{
public:
string addBinary(string a, string b)
{
...
分类:
其他好文 时间:
2015-01-12 17:43:48
阅读次数:
138
题目:
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
Ans...
分类:
编程语言 时间:
2015-01-12 16:44:08
阅读次数:
216
题目:
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
For example:
Given the below binary tree a...
分类:
编程语言 时间:
2015-01-12 16:40:36
阅读次数:
221
1. 红黑树(RED-BLACK TREE)引言:红黑树(RBT)可以说是binary-search tree的非严格的平衡版本。与之相应的是平衡二叉树(Balanced Binary Tree)又称之为AVL树(因为是G.M. Adelson-Velsky 和 E.M. Landis在1962年发...
分类:
编程语言 时间:
2015-01-12 15:56:55
阅读次数:
357
Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm's runtime complexity must be in the order of O(log
n).
If the target is not found in...
分类:
其他好文 时间:
2015-01-12 09:29:25
阅读次数:
119
一. 二叉堆的性质 堆是一种具有堆序性的完全二叉树. 作为一种完全二叉树, (假定空树的高度是-1)它的高度是floor(logN), 高度为h的结点有2^h到2^(h+1) - 1个, 父节点的下标为floor(i/2), 左孩子的下标为2i, 右孩子的下标为2i+1 而所谓堆序性就是(以最小堆为...
分类:
其他好文 时间:
2015-01-12 09:14:35
阅读次数:
133