Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
According to the definition of LCA on Wikipedia: “The lowest...
分类:
其他好文 时间:
2015-07-25 20:00:08
阅读次数:
146
解法一:递归 1 TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) 2 { 3 if (root == NULL || p == NULL || q == NULL) 4 retu...
分类:
其他好文 时间:
2015-07-25 18:17:20
阅读次数:
108
cv::threshold(GrayImg, Bw, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);//灰度图像二值化CV_THRESH_OTSU是提取图像最佳阈值算法。该方法在类间方差最大的情况下是最佳的,就图像的灰度值而言,OTSU给出最好的类间分离的阈值...
分类:
其他好文 时间:
2015-07-25 12:12:03
阅读次数:
310
后序遍历的遍历中,某一个节点要被输出,在两种情况下:当前节点的左右孩子为空;当前节点的左右孩子已经被访问。第一种情况非常容易判断第二种情况需要记录访问过的节点,显然当前节点如果有孩子,则对它的访问会紧跟在它的孩子节点之后,无论是左右。所以只需记录每次访问的节点,就Ok![1]http://www.c...
分类:
其他好文 时间:
2015-07-25 12:06:37
阅读次数:
96
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of ...
分类:
其他好文 时间:
2015-07-25 10:45:07
阅读次数:
114
04-树7. Search in a Binary Search Tree (25)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
To search a key in a binary...
分类:
其他好文 时间:
2015-07-25 10:44:32
阅读次数:
145
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = "great":
great
/ gr ...
分类:
其他好文 时间:
2015-07-25 10:44:04
阅读次数:
128
04-树8. Complete Binary Search Tree (30)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
A Binary Search Tree (BST) is ...
分类:
其他好文 时间:
2015-07-25 10:41:28
阅读次数:
193
Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which rep...
分类:
其他好文 时间:
2015-07-24 23:54:38
阅读次数:
107
题意:有n个数存放在数组a1[]中,然后数组a1[]生成数组a2[],a2[]生成a3[].....一直生成an[],公式是ai[k]=ai-1[k]&ai-1[k+1],现在如果把初始数据也就是数组a1[]里的某一个数换成另一个数,求所有数组的总和是多少。
分析:既然这里的数组生成公式里用到了位与运算,那么就用位运算来做了。
把数字写成二进制,公式的意思就是说同一数组的相邻数字的对应二进制位...
分类:
其他好文 时间:
2015-07-24 22:40:52
阅读次数:
149