【题目】
Given a string S and a string T, count the number of distinct subsequences of T in S.
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relati...
分类:
其他好文 时间:
2014-06-29 07:27:17
阅读次数:
210
算法分析:
循环算法和递归算法 无论时间效率还是空间效率都是前者高。递归算法在运行时,函数调用保存现场、开辟运行资源、返回回收资源都需要耗时。递归算法的参数表面是一个变量,实际上市一个栈。
结论1:
递归确实是一些复杂的问题处理起来简单明了,但是,就效率而言,递归算法的实现往往比循环算法耗费更多的时间和存储空间,也限制了递归的深度。所以,在具体的实现中,应尽可能把递归算法转换为等价...
分类:
其他好文 时间:
2014-06-20 13:18:09
阅读次数:
170
求两个正整数的最大公约数是一个很古老且很基本的问题,欧几里得在其著作《几何原本》中给出了高效的解法——辗转相除法,也叫做欧几里得算法。下面我们来看下求最大公约数的一些方法。
方法一
我们先来看欧几里得的辗转相除法。原理很简单,假设用f(x,y)表示x和y的最大公约数,我们令x>y,则有x=ky+b,如果一个数能够同时整除x和y,则必能同时整除b和y,而能够同时整除b和y的数也必能同时整除x和y,即x和y的公约数与b和y的公约数相同,因此二者的最大公约数也相同,则有f(x,y)=f(y,x%y),一...
分类:
其他好文 时间:
2014-06-20 11:10:03
阅读次数:
191
一直想要写的 二叉树 中序 先序 后序遍历算法
递归的太简单了,就不写了。关键是非递归版本。
先序:
我自己的版本:
void RootPreTraverse(Node* p)
{
Stack S;
while(S not empty)
{
p=S.top();
S.pop();
Show(p);
if(p->right!=null)
S...
分类:
其他好文 时间:
2014-06-20 10:55:49
阅读次数:
279
【题目】
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 tree and sum = 22,
5
/ 4 8
/ / 11 13 4
...
分类:
其他好文 时间:
2014-06-20 10:53:08
阅读次数:
181
【题目】
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be...
分类:
其他好文 时间:
2014-06-07 14:28:36
阅读次数:
215
摘要:MapReduce程序开发流程遵循算法思路、Mapper、Reducer、作业执行的步骤。...
分类:
其他好文 时间:
2014-06-07 13:42:08
阅读次数:
242
package test;
public class NumberFormatTest {
static String[] units = { "", "十", "百", "千", "万", "十万", "百万", "千万", "亿",
"十亿", "百亿", "千亿", "万亿" };
static char[] numArray = { '零', '一', '二', '...
分类:
编程语言 时间:
2014-06-07 13:15:10
阅读次数:
230
【题目】
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1
/ 2 5
/ \ 3 4 6
The flattened tree should look like:
1
2
3
4
\...
分类:
其他好文 时间:
2014-06-07 11:37:00
阅读次数:
153