二分查找伪代码:迭代Binary-Search(A,low,high,x)while(low<=high)
mid=(low+high)/2
if(A[mid]==x)
returnmid
elseif(A[mid]>x)
high=mid-1
else
low=mid+1
returnnull
二分查找伪代码:递归Binary-Search(A,low,high,x)
if(low>high)
returnnull
m..
分类:
编程语言 时间:
2015-03-08 17:24:45
阅读次数:
232
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.
/**
* Definition for binary tree
* struct Tree...
分类:
其他好文 时间:
2015-03-08 17:12:04
阅读次数:
103
DescriptionYou are to determine the value of the leaf node in a given binary tree that is the terminal node of a path of least value from the root of ...
分类:
其他好文 时间:
2015-03-08 12:59:07
阅读次数:
147
1.题目Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1
2
/
3
return [3,2,1].Note: Recursive solution is trivial, co...
分类:
其他好文 时间:
2015-03-08 11:47:11
阅读次数:
136
1.题目Given an array where elements are sorted in ascending order, convert it to a height balanced BST.2.解决方案1 struct Node{
TreeNode* t;
int l;
int r;
Node(vector &num, int l, int r)...
分类:
其他好文 时间:
2015-03-08 10:28:52
阅读次数:
148
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return ...
分类:
其他好文 时间:
2015-03-08 10:26:05
阅读次数:
1355
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return ...
分类:
其他好文 时间:
2015-03-07 21:18:26
阅读次数:
121
Symmetric Tree问题:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).思路: dfs我的代码:public class Solution { ...
分类:
其他好文 时间:
2015-03-07 19:58:45
阅读次数:
135
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the...
分类:
其他好文 时间:
2015-03-07 18:37:15
阅读次数:
367
Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".[Solution] 1 string addBinary(string a, string ...
分类:
其他好文 时间:
2015-03-07 18:36:26
阅读次数:
107