原题地址:https://oj.leetcode.com/problems/search-a-2d-matrix/题意:Write
an efficient algorithm that searches for a value in anmxnmatrix. This matrix has
the...
分类:
编程语言 时间:
2014-06-29 07:56:13
阅读次数:
321
K-Nearest Neighbors
The algorithm caches all training samples and predicts the response for a new sample by analyzing a certain number (K) of the nearest neighbors of the sample using voting, calcu...
分类:
其他好文 时间:
2014-06-20 11:51:33
阅读次数:
337
设计一个支持‘.' 和 '*' 的正则表达式匹配算法。
这个题复杂的地方在于对于 '*' 的处理,这个符号在正则表达式中被称为贪婪型的量词。这个量词在实际匹配过程中也是尽可能多的匹配直到词尾或者不匹配成功才结束,然后如果其后面还有没有匹配的,则回退到合适的位置,然后才进行下一个匹配。正则表达式中的匹配优先与回溯大概也就是这个意思。关于正则表达式这方面的知识,有兴趣可以读读《精通正则表达式》的第4章表达式的匹配原理。
回到本题,正因为 '*'的特殊性,我们在分类的时候选择根据 '*' 来进行,分类后其子问题也...
分类:
其他好文 时间:
2014-06-20 09:40:42
阅读次数:
207
Bubble sortBubble sort, sometimes incorrectly
referred to as sinking sort, is a simple sorting algorithm that works by
repeatedly stepping through the...
分类:
其他好文 时间:
2014-06-07 11:30:59
阅读次数:
390
1. 普通的二分查找2. 查找最左边的值3. 查找最右边的值Worst case
performance: O(log n)Best case performance: O(1)Average case performance: O(log
n)Worst case space complexity...
分类:
其他好文 时间:
2014-06-07 11:19:48
阅读次数:
248
随机生成[0,n)中不重复的m个数。 1 class Random { 2 public: 3
Random(int n, int m):n(n), m(m) {} 4 void generate() { 5 srand(time(NULL)); 6
...
分类:
其他好文 时间:
2014-06-07 08:42:38
阅读次数:
178
算法导论上面快速排序的实现。代码:def partition(array, left, right):
i = left-1 for j in range(left, right): if array[j] <= array[right]: i += ...
分类:
编程语言 时间:
2014-06-06 18:18:13
阅读次数:
351
/** * jQuery MD5 hash algorithm function * * *
Calculate the md5 hash of a String * String $.md5 ( String str ) * * *
Calculates the MD5 ha...
分类:
Web程序 时间:
2014-06-05 21:50:52
阅读次数:
612
An iterative algorithm takes one step at a
time, ensuring that each step makes progress while maitining the loop
invariant.A paradigm shift:View an al...
分类:
其他好文 时间:
2014-06-02 19:20:20
阅读次数:
286
分析:
* 可以匹配任意个字符,包括0个多个连续的*的作用相当于1个*。* 后无其他字符,则直接匹配出现*p为 *,而*s为字符时,我们有两种选择,一种是跳过*p指示的*,也就是令*匹配0个字符,继续向后匹配。
一种是我们需要用* 匹配多个字符,才能完成匹配。
* 后有其他字符,则在s串中向后找与该非*字符匹配的字符,若没找到,则不匹配,若找到了,则会有不同的情况。
...
分类:
其他好文 时间:
2014-06-02 15:14:29
阅读次数:
271