解题思路
给一个排序数组和一个数,寻找该数在数组的位置或者插入位置。本题考查的还是二分查找。二分查找返回的结果就是该数在数组中该插入的位置。
代码实现...
分类:
其他好文 时间:
2014-06-11 00:55:14
阅读次数:
205
题目
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.
方法
使用两个矩阵,分别记录每一行连续的1的个数以及每一列连续的1的个数。
public int maximalRec...
分类:
其他好文 时间:
2014-06-11 00:24:51
阅读次数:
343
以i为根节点时,其左子树构成为[0,...,i-1],其右子树构成为[i+1,...,n]构成。根结点确定时,左子树与右子树的结点个数都是确定的。这样就可以把这个问题化成子问题。因此可以用动态规划解。Sigma(左边的子树可能状态
* 右边子树可能状态) = 当前个数的结点可能的状态数。public...
分类:
其他好文 时间:
2014-06-10 12:46:05
阅读次数:
175
第一次看到accept,心里有点小开心/** * Definition for binary tree
* public class TreeNode { * int val; * TreeNode left; * TreeNode right; *
TreeNode...
分类:
其他好文 时间:
2014-06-10 11:53:41
阅读次数:
241
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 / \ ...
分类:
其他好文 时间:
2014-06-10 11:51:42
阅读次数:
213
奇偶校验位是一个表示给定位数的二进制数中1的个数是奇数还是偶数的二进制数。奇偶校验位是最简单的错误检测码。A
parity bit, or check bit is a bit added to the end of a string of binary code
that indicates wh...
分类:
Web程序 时间:
2014-06-10 11:51:03
阅读次数:
288
binary search\sort\find operations
status InsertNode(Node* root, data x, Node* father)
{
if(root==NULL)
{
if(father==NULL)
Tree empty;
else
{
if(xdata)
{
father->left=new Node//inital l...
分类:
其他好文 时间:
2014-06-10 08:09:49
阅读次数:
234
分析:
问题是将给定的二叉树变换成令一种形式,这种类型的问题,其模式是,将左子树变换成某种形式,右子树也变换成这种形式,然后再与根结点按规定的方式连接起来,那么整体就变换完成了。这个题我们就可以采用这种形式,麻烦的地方就是在进行连接的时候,我们假设根为root,左子树变换后的根为root_left,右子树变换后的根为 root_right,那么连接的时候应该是root->right = root...
分类:
其他好文 时间:
2014-06-10 07:27:10
阅读次数:
201
问题:
给定一个有序链表,生成对应的平衡二叉搜索树。
分析
见Convert
Sorted Array to Binary Search Tree
实现:
TreeNode *buildTree(ListNode* head, ListNode *end){
if(head == NULL || head == end)
return NULL;
...
分类:
其他好文 时间:
2014-06-10 07:17:29
阅读次数:
264
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...
分类:
其他好文 时间:
2014-06-10 00:54:41
阅读次数:
313