1. 递归解法
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
cl...
分类:
其他好文 时间:
2014-06-08 16:51:59
阅读次数:
199
本题有两个考点:
1 求逆序数的性质
计算逆序数的公式, 一个数arr[i]从前面放到后面,必然会有n-arr[i]-1个数比这个大,那么就有n-arr[i]-1个逆序数增加,同时因为前面少了个arr[i]数,那么就必然有arr[i]个(加上零)数比起小的数失去一个逆序数,总共失去arr[i]个逆序数,所以新的逆序数为增加了n-arr[i]-1-arr[i]个逆序数(当然有可能是减小了,视ar...
分类:
其他好文 时间:
2014-06-08 15:52:20
阅读次数:
275
【题目】
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
You may only use constant extra space.
For example,
Given the following binary tre...
分类:
其他好文 时间:
2014-06-08 15:46:22
阅读次数:
303
OpenCV 2.2 以及后面的版本取消掉了 CvvImage.h 和CvvImage.cpp 两个文件,直接导致了苦逼的程序员无法调用里面的显示函数来将图片显示到 MFC 的 Picture Control 控件中。为此,网上很多人表示只要将那两个文件人为的提取出来然后放到工程里面就解决问题了,也提供了两个文件的下载,但是这麻烦不说,还会导致一些奇奇怪怪的报错(至少本人是这样的,很崩溃!)。所以...
分类:
其他好文 时间:
2014-06-08 15:28:41
阅读次数:
269
问题:
给定二叉树的前序和中序遍历,重构这课二叉树.
分析:
前序、中序、后序都是针对于根结点而言,所以又叫作先根、中根、后根(当然不是高跟)。
前序:根 左 右
中序:左 根 右
对二叉树,我们将其进行投影,就会发现个有趣的事:
发现投影后的顺序,恰好是中序遍历的顺序,这也就是为什么在构造二叉树的时候,一定需要知道中序遍历,因为中序遍历决定了结点间的相对左右位置关系。所...
分类:
其他好文 时间:
2014-06-08 15:20:12
阅读次数:
214
如果希望对显示在MFC Picture Control 控件里的图像进行操作,比如画线画点之类的,可以利用 OpenCV 结合 MFC 本身的鼠标响应函数来实现。
如何将图像显示到 Picture Control 控件不谈,本文是采用的这篇博客所介绍的方法实现的。 点击打开链接
给对话框添加 WM_LBUTTONDOWN 鼠标左键点击消息,在消息响应函数中添加如下代码:
void CMFC...
分类:
其他好文 时间:
2014-06-08 15:11:14
阅读次数:
210
问题:
由中序和后序遍历构造二叉树。
分析:
Construct Binary Tree from Preorder and Inorder
Traversal
//实现
TreeNode *addNode(vector &inorder, int s1, int end1, vector &postorder, int s2, int end2)
{
...
分类:
其他好文 时间:
2014-06-08 09:56:52
阅读次数:
206
UIImage 是一种比较有难度的显示图片的方式,UIImage 可以从文件或者 ImageData
中来显示图片。如果可以图形化操作,建议使用 ImageView 这个 Control 来显示图片,毕竟是图形化可视操作。当从 ImageData
中创建图片的时候,一定要注意图片的大小和尺寸,因为这...
分类:
移动开发 时间:
2014-06-08 01:16:59
阅读次数:
401
PathsumDescription: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 equa...
分类:
其他好文 时间:
2014-06-08 01:11:46
阅读次数:
395
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.Fo...
分类:
其他好文 时间:
2014-06-07 16:55:09
阅读次数:
173