1 /* 2 Design and implement a data structure
for Least Recently Used (LRU) cache. It should support the following operations:
get and set. 3 ...
分类:
其他好文 时间:
2014-06-11 13:08:46
阅读次数:
297
原题地址:https://oj.leetcode.com/problems/powx-n/题意:Implement
pow(x,n).解题思路:求幂函数的实现。使用递归,类似于二分的思路,解法来自Mark Allen Weiss的《数据结构与算法分析》。代码:class
Solution: #...
分类:
编程语言 时间:
2014-06-11 08:59:33
阅读次数:
317
class Solution {public: char *strStr(char
*haystack, char *needle) { if (haystack == NULL || needle == NULL) return NULL;
int wpos[25...
分类:
其他好文 时间:
2014-06-11 07:40:05
阅读次数:
200
题目
Implement int sqrt(int x).
Compute and return the square root of x.
方法一
使用二分查找,注意int的边界问题,使用除法。
public int sqrt(int x) {
if (x <= 1) {
return x;
...
分类:
其他好文 时间:
2014-06-10 06:49:45
阅读次数:
274
1 //use this to implement platform-cross
new-line.2 StringBuilder sb = new StringBuilder();3
sb.append(System.getProperty("line.separator"));
分类:
其他好文 时间:
2014-06-09 00:35:09
阅读次数:
213
该形式的工厂模式是我项目中用到的方法,属于很成熟的模版,读者可以直接拿来在自己项目中使用。个人感觉这种方法真正做到了“开放封闭”的原则,最大好处是用户产品类的设计完全不依赖于该模式的实现,比如提供必须的相关函数等。如果不理解工厂模式的话,请参考网上其它文章,本实现在理解上有一点小小的难度。好东西,大家慢慢享用,话不多说,先放代码!
首先是产品基类,它相当于一个接口,产品需要有什么动作就写在这里吧...
分类:
其他好文 时间:
2014-06-08 14:56:18
阅读次数:
202
字符串匹配这也是个老题了,方法主要有下面4种,
1. 暴利破解法(BF),这个没啥说的,就是一轮一轮的比较,知道遇到相匹配的,这个的时间复杂度为O(n^2)。
2. KMP,这应该是字符串匹配领域中最长听说的算法了吧。
3. Horspool算法,这个不常听说,但是也是很有名的。
4. Boyer-Moore,这个听说过的人应该也不会很多,这个算法在大量字符串的情况下,效率是最高的,能达到kmp的3到4倍。
上面四种算法都很重要,一般标准库中的字符串匹配都使用的是暴力法。
上面四种算法详细的见我下面的这几篇...
分类:
其他好文 时间:
2014-06-08 03:19:54
阅读次数:
187
不使用C程序已有函数,模拟C++的strstr函数
strstr函数--输出主串的子串及其后面的所有字符...
分类:
编程语言 时间:
2014-06-08 02:14:50
阅读次数:
192
Although apply and call can implement same
function. However, there is a litter different between them.Please pay attention
to look at the examples be...
分类:
移动开发 时间:
2014-06-07 21:53:15
阅读次数:
331
Implement atoi to convert a string to an integer.
Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca...
分类:
其他好文 时间:
2014-06-07 12:21:30
阅读次数:
284