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. 我的vim配置

    之前都在虚拟机下面捣鼓Linux,有种隔靴搔痒的感觉.为了更快地熟悉Linux系统,重新安装了Ubuntu,首先就是配置vim. 下面是我的vim配置,为了方便,我在代码后添加注释说明. 1.配置C/ ...

  2. 1962-Fibonacci

    描述 This is an easy problem.I think Fibonacci sequence is familiar to you.Now there is another one. H ...

  3. poj 1487 Single-Player Games

    主要考察表达式的解析和高斯消元!!! #include<iostream> #include<stdio.h> #include<algorithm> #inclu ...

  4. http://blog.csdn.net/xyang81/article/details/7292380

    http://blog.csdn.net/xyang81/article/details/7292380

  5. java jdk自带程序分析(内存分析/线程分析)

    周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令. 1.1.Jstack 1.1   jstack能得到运行jav ...

  6. CentOS7.1配置远程桌面

    网上看了很多资料,完全是乱的. 我使用的是CentOS7.1的系统.我的要求是windows的客户机可以远程访问CentOS系统. 1,首先需要检查一下服务器是否已经安装了VNC服务,检查服务器的是否 ...

  7. linux bash脚本把A和B文件中有相同ID的B文件的内容输出到文件C

    bash脚本把A和B文件中有相同ID的B文件的内容输出到文件C. Aid文件:ID001.1ID032.1ID090.10 Bfilt文件:XX XX XXX ID001.1 XXX999999999 ...

  8. mssql查找备注(text,ntext)类型字段为空的方法

    在sql语句中,如果查找某个文本字段值为空的,可以用select * from 表 where 字段='' ,但是如果这个字段数据类型是text或者ntext,那上面的sql语句就要出错了. 解决办法 ...

  9. 自定义一个compass可编译的目录结构

    在学习compass的过程中, 根绝文档说明,如果使用compass create myObject命令会创建一个标准的Compass项目目录结构,如下图: 此时如果使用compass compile ...

  10. 最受 Web 开发者欢迎的 NoSQL 和关系数据库

    Web应用离不开数据库,目前市场上有种类繁多数据库可供开发者选择,例如SQL.NoSQL.键值.图谱数据库等等.关于不同数据库在开发者中的受欢迎程度也是仁者见仁智者见智,但是通过统计亚马逊这样的公共云 ...