Description: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 t...
分类:
其他好文 时间:
2015-07-04 18:21:09
阅读次数:
91
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 = 2...
分类:
其他好文 时间:
2015-07-04 15:32:56
阅读次数:
95
Binary SearchJonBentley以前说过类似的话:“90%的程序猿无法正确实现二分查找算法就冲着这句话去写binary searchbinary_search 的算法实现部分/*******************************************************...
分类:
其他好文 时间:
2015-07-04 15:15:53
阅读次数:
86
To be honest, I do not know whether this problem is designed to let you use stacks. Anyway, I don't. Here are my codes, both BFS and DFS version. 1 .....
分类:
其他好文 时间:
2015-07-04 12:27:08
阅读次数:
115
描述: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 a substring of B? For...
分类:
其他好文 时间:
2015-07-04 10:57:26
阅读次数:
99
This link has a very concise and fast solution based on binary search. Spend some time reading it and make sure you understand it. It is very helpful....
分类:
其他好文 时间:
2015-07-04 00:41:54
阅读次数:
120
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class...
分类:
其他好文 时间:
2015-07-03 23:31:49
阅读次数:
358
题意:从左到右统计将同一层的值放在同一个容器vector中,要求上下颠倒,左右不颠倒。思路:广搜逐层添加进来,最后再反转。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5...
分类:
其他好文 时间:
2015-07-03 23:19:55
阅读次数:
139
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class...
分类:
其他好文 时间:
2015-07-03 22:09:52
阅读次数:
127
思路:递归解决,在返回root前保证该点的两个孩子已经互换了。注意可能给一个Null。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *...
分类:
其他好文 时间:
2015-07-03 22:00:31
阅读次数:
232