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. [转]深度理解依赖注入(Dependence Injection)

    http://www.cnblogs.com/xingyukun/archive/2007/10/20/931331.html 前面的话:提到依赖注入,大家都会想到老马那篇经典的文章.其实,本文就是相 ...

  2. jquery中json数据转换为字典

    首先在前台页面中的json数据为 var recipe = {}; recipe["name"] = $("#name").val(); recipe[&quo ...

  3. [Unity3D]支持的视频格式

    Unity3d只支持 .mov, .mpg, .mpeg, .mp4, .avi, .asf这些格式.

  4. 团体程序设计天梯赛-练习集L2-002. 链表去重

    L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除 ...

  5. 作为 .Net 攻城师,所必需掌握的 .Net Profiling 技术

    众所周知,性能问题是所有实用应用在迭代过程中必然要面对的问题.对于此类问题,简单地投入更多硬件资源的做法可能会取得一定效果.但总的来看,此类做法的边际成本是不断上升的.换言之,随着性能需求的上涨,要换 ...

  6. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  7. 扩展DJANGO的LISTVIEW

    不用MODEL,不用QUERYSET,而用get_queryset方法来扩展LISTVIEW, 从而实现特定过滤或搜索功能. class DVListView(ListView): template_ ...

  8. 5.查找最小的k个元素(数组)

    题目: 输入n个整数,输出其中最小的k个,例如输入1,2,3,4,5,6,7,8这8个数,则最小的4个是1,2,3,4(输出不要求有序) 解: 利用快速排序的partition,算导上求第k大数的思想 ...

  9. 实例讲解Nginx下的rewrite规则

    一.正则表达式匹配,其中:* ~ 为区分大小写匹配* ~* 为不区分大小写匹配* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配二.文件及目录匹配,其中:* -f和!-f用来判断是否存在文件* ...

  10. java synchronized wait

    在多个线程要互斥访问数据,但线程间需要同步时——例如任务分多个阶段,特定线程负责特定阶段的情况,经常合作使用synchronized 和 wait() /** * * 计算输出其他线程锁计算的数据 * ...