Leetcode OJ : Implement strStr() [ Boyer–Moore string search algorithm ] python solution
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的更多相关文章
- [leetcode 27]Implement strStr()
1 题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...
- [LeetCode] 28. Implement strStr() 实现strStr()函数
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【leetcode】Implement strStr() (easy)
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Java for LeetCode 028 Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Java [leetcode 28]Implement strStr()
题目描述: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...
- [LeetCode] 28. Implement strStr() 解题思路
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Leetcode 28——Implement strStr()
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- leetcode(57)- Implement strStr()
题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...
- [leetcode]28. Implement strStr()实现strStr()
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
随机推荐
- 用in判断input中的placeholder属性是否在这个对象里
<input id="test"> var ele = document.getElementById("test"); if("plac ...
- PAT-乙级-1023. 组个最小数 (20)
1023. 组个最小数 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 给定数字0-9各若干个.你可以以 ...
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结,为了自己复习,也希望对后来者能有所帮助,如果有差错的地方还请各位多多指教(本文所有程序均通过VC 6.0运行) 1.cin 2.cin.get ...
- 【leetcode】Permutations II (middle)
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- UIWebView和UIWebViewDelegate的基本用法
UIWebView和UIWebViewDelegate的基本用法 一.UIWebView主要有三种方法实现页面的装载,分别是: 1. (void)loadRequest:(NSURLRequest * ...
- CURL与PHP-CLI的应用【CLI篇】
CLI的普通应用 什么是PHP-CLI php-cli是php Command Line Interface的简称,即PHP命令行接口,在windows和linux下都是支持PHP-CLI模式的; 为 ...
- live555源码研究(三)------UsageEnvironment类
一.UsageEnvironment类作用 1,不使用的时候回收当前的使用环境. 2,对返回结果消息和错误消息的维护. 二.类UsageEnvironment继承关系图
- Servlet课程0426(九)Servlet服务器端创建Cookie和客户端读取Cookie
服务器端创建Cookie: Win7默认Cookie位置 C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Cookies Cookie ...
- 这些废弃的 HTML 标签不要用
HTML 已经发展了多年,现在 W3C 已经发布了 HTML 5.1 的提案推荐标准,一些陈旧废弃的标签已经在后继的标准中逐渐消失.这里为大家列出那些已经被废弃 HTML 标签,看看你是不是还在使用它 ...
- 华为荣耀6PLUS 秒杀苹果
华为荣耀6PLUS 秒杀苹果. [ az09 ] 于:2015-02-21 12:36:47 复:4036020 刚入手华为荣耀6PLUS,双4G版,在温哥华使用,效果很好. 首先很漂亮,感觉去掉HO ...