Problem FPaths through the
HourglassInput:Standard InputOutput:Standard OutputTime Limit:2 SecondsIn the
hourglass to the right a path is marked. A pa...
分类:
其他好文 时间:
2014-05-16 05:34:47
阅读次数:
307
class Solution {public: bool search(int A[],
int n, int target) { if (n A[mid]) { right = mid; sep = A[mid]; ...
分类:
其他好文 时间:
2014-05-15 09:29:52
阅读次数:
177
#include
#include
using namespace std;
//下面一个移位是一样的,>>相当于除去2,主要是要用right-left,否则对于大数据来说会产生溢出问题。切记
int binarySearch(int arr[],int len,int number)
{
int left=0;
int right=len-1;
in...
分类:
其他好文 时间:
2014-05-15 07:14:38
阅读次数:
272
题意:给定一棵perfect binary tree,将它每一个节点的next指针都指向该节点右边的节点
思路:dfs
在connect一棵树的时候,需要知道这棵树的根节点和它右边的节点
1.将树的根节点和它右边的节点连接起来
2.递归地将左子树connect起来,需要知道左子树节点和右子树节点
3.递归地将右子树connect起来,需要知道右子树节点和根右边的节点的左子树节点
递归函数为:
void connect(TreeLinkNode *root, TreeLinkNode *sibling)
表...
分类:
其他好文 时间:
2014-05-15 07:14:04
阅读次数:
289
题意:给定一棵任意二叉树(不一定是perfect binary tree),将它每一个节点的next指针都指向该节点右边的节点
思路:bfs
这里不能用dfs了,只能用bfs
bfs遍历将同一层的节点存放在同一个数组里,
然后在遍历每个数组,将前面的节点和后面的节点connect起来,
最后一个节点和NULL connect起来
需要定义一个新的struct结构,保存指向每个节点的指针和该节点所在的层
复杂度:时间O(n), 空间O( n)...
分类:
其他好文 时间:
2014-05-15 06:12:13
阅读次数:
294
1、
??
Populating Next Right Pointers in Each Node
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate...
分类:
其他好文 时间:
2014-05-15 04:57:36
阅读次数:
221
题目
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.The first integer...
分类:
其他好文 时间:
2014-05-15 03:41:11
阅读次数:
257
Description
Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the Universit...
分类:
其他好文 时间:
2014-05-15 00:20:39
阅读次数:
332
switch 语句int x = 10switch(x) case
1:print(“sfsd”)breakcase 2:print(“dsdf”)breakdefaultprint(“right”)break
分类:
其他好文 时间:
2014-05-14 23:47:11
阅读次数:
263
1、二分查找常见错误:死循环:循环体外的初始化条件,与循环体内的迭代步骤,
都必须遵守一致的区间规则,也就是说,如果循环体初始化时,是以左闭右开区间为边界的,那么循环体内部的迭代也应该如此.如果两者不一致,会造成程序的错误.溢出:middle=left+(right-left)/2终止条件:一般来说...
分类:
其他好文 时间:
2014-05-14 23:26:03
阅读次数:
402