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 ...
 
随机推荐
- centos7 更新yum安装源
			
系统自带的yum安装源有些软件找不到 这里我们使用阿里云的源 1.加源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/re ...
 - 【斜率DP】BZOJ 3675:[Apio2014]序列分割
			
3675: [Apio2014]序列分割 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 1066 Solved: 427[Submit][Statu ...
 - 如何优化 Android Studio 启动、编译和运行速度?
			
作为一名 Android 程序员,选择一个好的 IDE 工具可以使开发变得非常高效,很多程序员喜欢使用 Google 的 Android Studio来进行开发,但使用起来有时会出现卡顿等问题.本文介 ...
 - Spring/Hibernate 应用性能优化的7种方法
			
对于大多数典型的 Spring/Hibernate 企业应用而言,其性能表现几乎完全依赖于持久层的性能.此篇文章中将介绍如何确认应用是否受数据库约束,同时介绍七种常用的提高应用性能的速成法.本文系 O ...
 - weak_ptr的一点认识
			
近期在补充和梳理C++方面的知识的时候,遇到了WeakPtr这个概念和用法,不甚明白,Google出了一堆文字,包括Boost的shared_ptr和weak_ptr的比较,以及其他一些博客里面给的例 ...
 - 在非MFC程序中引用CString
			
CString在当今软件设计界里还是小有名气的,说它是MFC中使用的最多的类一点也不过,然而在使用sdk编windows程序的时候,确不能利用CString类,只能用sdk的运行时库,比如strlen ...
 - php关于private、public成员变量访问问题
			
如果类里面定义了__get($name)方法,则不论类的private成员还是public成员,都能够在类的外面通过类似$class->name访问到.如果是public变量,则不会自动调用ge ...
 - 关于DataTables一些小结
			
最近项目中使用了DataTables,故小结了一下. 导入CSS文件<link rel="stylesheet" href="<%=base %>/js ...
 - live555源码研究(四)------UserAuthenticationDatabase类
			
一.UserAuthenticationDatabase类作用 1,用户/密码管理 2,鉴权管理 二.类UserAuthenticationDatabase继承关系图 ...
 - Android:监听ListView
			
本文目录 监听ListView点击事件 监听ListView滚动事件 监听ListView点击事件 使用监听器OnItemClickListener package com.example.tests ...