Binary String Matching
时间限制:3000 ms | 内存限制:65535 KB
难度:3
描述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...
分类:
其他好文 时间:
2015-03-31 09:12:58
阅读次数:
122
Java集合中二分查找算法实现
Arrays.binarySearch实现了对有序数组特定区间的二分查找,虽然我们觉得很简答,但是阅读源码的确能看到实现这些库的优秀技巧,总是在追求完美和高效。
值得学习的地方有:
(1)边界检查;
(2)求中位数的时候使用位移操作,而不是 x/2;
(3)如果查找的元素不在数组中,通过返回值昭示了应该插入的位置,而不是直接返回-1;...
分类:
编程语言 时间:
2015-03-30 18:50:14
阅读次数:
165
题目描述:
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming
weight).
For example, the 32-bit integer ’11' has binary representa...
分类:
其他好文 时间:
2015-03-30 18:42:17
阅读次数:
128
题目:Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1....
分类:
其他好文 时间:
2015-03-30 16:24:02
阅读次数:
129
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....
分类:
其他好文 时间:
2015-03-30 13:24:31
阅读次数:
112
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 and sum ...
分类:
其他好文 时间:
2015-03-30 13:20:37
阅读次数:
84
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-03-30 13:14:32
阅读次数:
89
题目:
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
思路:根据前序和中序的特点 递归调用创建二叉树
#include
#include
u...
分类:
其他好文 时间:
2015-03-30 11:26:36
阅读次数:
122
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
#include
#include
#include
using namespace std;
struct TreeNode {
int val;...
分类:
其他好文 时间:
2015-03-30 11:24:41
阅读次数:
121
和上面的题目相似 思路也是类似
Tree* helpersecond(vector& inorder,int in_begin,int in_end,vector& post,int post_begin,int post_end)
{
Tree* root =NULL;
int mid;
int i;
if(in_begin > in_end)
{
return NULL;
}...
分类:
其他好文 时间:
2015-03-30 11:24:10
阅读次数:
117