class Solution {
public:
int strStr(char *haystack, char *needle) { int i = , skip[];
char *str = haystack, *substr = needle;
int len_src = strlen(str), len_sub = strlen(substr);
// preprocess
for (i = ; i < ; i++)
skip[i] = len_sub;
int last = len_sub - ;
for (i = ; i < last;i++)
skip[substr[i]] = last - i;
// search
int pos = , j;
while (pos <= len_src-len_sub) {
j = last;
while (j>= && str[pos+j]==substr[j])
j--;
if (j<)
return pos;
pos += skip[str[pos+last]];
}
return -;
}
};

Leetcode OJ : Implement strStr() [ Boyer–Moore string search algorithm ] python solution的更多相关文章

  1. [leetcode 27]Implement strStr()

    1 题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...

  2. [LeetCode] 28. Implement strStr() 实现strStr()函数

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  3. 【leetcode】Implement strStr() (easy)

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  4. Java for LeetCode 028 Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  5. Java [leetcode 28]Implement strStr()

    题目描述: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...

  6. [LeetCode] 28. Implement strStr() 解题思路

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  7. Leetcode 28——Implement strStr()

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  8. leetcode(57)- Implement strStr()

    题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...

  9. [leetcode]28. Implement strStr()实现strStr()

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

随机推荐

  1. java中四种引用类型

    java中四种引用类型  今天看代码,里面有一个类java.lang.ref.SoftReference把小弟弄神了,试想一下,接触java已经有3年了哇,连lang包下面的类都不了解,怎么混.后来在 ...

  2. ECSHOP报错误Deprecated: preg_replace(): The /e modifier is depr

    http://www.ecshoptemplate.com/article-1850.html

  3. tomcat部署javaweb项目的三种方式

    一.将项目文件夹或war包直接拷贝到tomcat的webapps下 二.在Tomcat\conf\Catalina\localhost下建立xml文件 修改内容如下<Context path=& ...

  4. linux usermod修改用户所在组方法

    usermod 用户名 -g 组名 -g<群组> 修改用户所属的群组. -G<群组> 修改用户所属的附加群组.

  5. SPRING IN ACTION 第4版笔记-第九章Securing web applications-008-使用非关系型数据库时如何验证用户(自定义UserService)

    一. 1.定义接口 Suppose that you need to authenticate against users in a non-relational database suchas Mo ...

  6. java:I/O 根据用户输入反馈信息

    import java.io.*; class userInputIO{ //Java中成员变量有默认初始化,也就是如果不显式设置初始值的话就会被初始化为其类型的默认值(0.false.null等). ...

  7. CSS+DIV 布局三种定位方式

    一.普通流 普通流中元素框的位置由元素在HTML中的位置决定.块级元素从上到下依次排列,框之间的垂直距离由框的垂直margin计算得到.行内元素在一行中水平布置. 二.定位 1.相对定位 被看作普通流 ...

  8. Struts中的 saveToken的方法

    Struts中的 saveToken的方法     saveToken防止2次提交的问题 struts有自带的Token(令牌)的机制来解决重复提交(包括后退,刷新等).举例: 假设:假设有一个新增用 ...

  9. 【iOS开发】iOS7 兼容及部分细节

    1:statusBar字体为白色 在plist里面设置View controller-based status bar appearance 为 NO:设置statusBarStyle 为 UISta ...

  10. 数据备份--dump

    数据中 心操作大量的数据.当遭到破坏时,这就是一场灾难.这时候需要备份来恢复,及时你又大量的备份数据都没用,备份也肯定不是在浪费时间.你也许很幸运从 来没有经历过数据丢失.但是, 由于这种事情极少发生 ...