这两道题用递归的解法都很简单,只是稍有不同。下面是AC代码: 1 /** 2 * Given a
binary tree, find its minimum depth. 3 * the minimum depth is the number of
nodes along th...
分类:
其他好文 时间:
2014-05-10 08:47:32
阅读次数:
271
这道题采用动态规划,可是我一开始没有想到。后来参考了discuss中前辈的代码和思路,才想通的。
方法二是因为每一步只和上一步的内容相关,所以可以只用O(n)的空间复杂度。下面是AC代码: 1 /** 2 * Solution DP 3 * we keep
a m*n matri...
分类:
其他好文 时间:
2014-05-10 08:43:12
阅读次数:
319
这道题因为不仔细的缘故两次过,与Maximum Depth of Binary
Tree问题类似,区别在于这个问题中,如果一个节点左子树为空、右子树有值,则该节点的深度应取决于右子树,而不能直接取min{左,右} 1 /** 2 *
Definition for binary tree 3 * .....
分类:
其他好文 时间:
2014-05-10 01:40:13
阅读次数:
293
一.最长公共子序列(LCS Longest Common
Subsequence)第一,先说区别,最长公共子串和最长公共子序列是不一样的。最长公共子串不许是连续的,而最长公共子序列可以是不联系的。网络上解释的子序列:一个字符串S,去掉零个或者多个元素所剩下的子串称为S的子序列。最长公共子序列就是寻找...
分类:
其他好文 时间:
2014-05-10 01:12:20
阅读次数:
370
Given a binary tree, find the maximum path
sum.The path may start and end at any node in the tree.For example:Given the
below binary tree, 1 ...
分类:
其他好文 时间:
2014-05-07 09:36:09
阅读次数:
300
当使用移动设备进行触控操作时,最常用的就是轻击、按住屏幕或者手势操作,jQuery Mobile可以通过绑定的触控事件来响应使用者的特定触控行为。一、轻击与按住直接上代码(一切皆在代码中,细细品吧!)
练习
<meta name="viewport" content="width=device-width,
initial-scale=1.0, maximum-scale=1....
分类:
移动开发 时间:
2014-05-07 04:45:59
阅读次数:
426
为了方便说明和更加直观的展示jquerymobile的页面初始化过程以及各个事件的触发过程,我绘制了一幅流程图:图中用红色框圈起来的是界面中的事件,测试代码如下:
练习
<meta name="viewport" content="width=device-width,
initial-scale=1.0, maximum-scale=1.0, user-scalable=0;...
分类:
移动开发 时间:
2014-05-07 04:40:07
阅读次数:
450
维护两个单调队列,一个存储当前点之前的最大值。
另外一个存储当前点之前的最小值。
若最大值与最小值之间的差大于k,那么就把最大值和最小值中位置靠前的往后移。
#include
#include
#include
#include
#include
using namespace std;
//#define INF ((1<<30)-1)
#define INF 0xfffff
#defin...
分类:
其他好文 时间:
2014-05-04 09:23:04
阅读次数:
372