码迷,mamicode.com
首页 >  
搜索关键字:算法    ( 83296个结果
LeetCode: Distinct Subsequences [115]
【题目】 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
LeetCode: Path Sum II [113]
【题目】 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
快速排序
常规快速排序 快速排序的优化...
分类:其他好文   时间:2014-06-20 09:22:36    阅读次数:159
LeetCode: Populating Next Right Pointers in Each Node [116]
【题目】 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
Hadoop之MapReduce程序开发流程
摘要:MapReduce程序开发流程遵循算法思路、Mapper、Reducer、作业执行的步骤。...
分类:其他好文   时间:2014-06-07 13:42:08    阅读次数:242
java实现 阿拉伯数字转换为汉字数字 算法
package test; public class NumberFormatTest { static String[] units = { "", "十", "百", "千", "万", "十万", "百万", "千万", "亿", "十亿", "百亿", "千亿", "万亿" }; static char[] numArray = { '零', '一', '二', '...
分类:编程语言   时间:2014-06-07 13:15:10    阅读次数:230
LeetCode: Flatten Binary Tree to Linked List [114]
【题目】 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
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!