题目描述:
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
代码:
int Solution::strStr(char *haystack, char *needle)
{
...
分类:
其他好文 时间:
2014-11-18 11:47:35
阅读次数:
161
问题描述:
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest p...
分类:
其他好文 时间:
2014-11-17 22:52:44
阅读次数:
229
Implement int sqrt(int x).Compute and return the square root of x.Analysis:Using binary search to find the solution. However, what need to be consider...
分类:
其他好文 时间:
2014-11-17 01:40:04
阅读次数:
205
Implement pow(x,n).如何实现pow(x,n),最原始的方法是用一层循环,求n个x的乘积,代码如下: 1 class Solution { 2 public: 3 double pow(double x, int n) { 4 if(n>1);14 ...
分类:
其他好文 时间:
2014-11-16 00:26:37
阅读次数:
213
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这个题应该就是求子串的问题,改进的方法是kmp算法。...
分类:
其他好文 时间:
2014-11-14 19:36:52
阅读次数:
254
Implement pow(x,n).直接把x自乘n-1次很容易实现,时间复杂度O(n).实际上,x^n = x^(n/2) * x^(n/2), 这样只需要求一次x^(n/2),再做一次乘操作即可,T(n) = T(n/2) + c, T(n) = lbn. (参见 CLRS 主定理)同时要注意两...
分类:
其他好文 时间:
2014-11-14 19:30:22
阅读次数:
216
类实现一个接口时,它必须实现该接口的所有部分(方法和属性等),效果相当于类要表明:“我同意履行这个接口所定义的协定。”从抽象类继承实现了“is-a(是一种)”关系,实现接口时一种“implement(实现)”关系,区别在于:举个例子:汽车是一种运载工具,它可以实现CanBeBoughtWithABi...
Implement strStr()Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这里用的BF算法...
分类:
其他好文 时间:
2014-11-13 18:21:30
阅读次数:
112
// strstr.c查找完全匹配的子字符串#include#includechar *my_strstr(const char *s1,const char *s2){ const char *p=s1; const int len=strlen(s2); for(;(p=str...
分类:
其他好文 时间:
2014-11-12 07:06:29
阅读次数:
126
$value) { if (stristr($value, $StrFiltrate)) //3.保证or/Or/oR/OR之类的提交不会成功(这是个比较安全的防止SQL注入的函数,现对于strstr()函数而言) { return true; } } return false;}//合...
分类:
Web程序 时间:
2014-11-10 23:20:20
阅读次数:
246