28. Implement strStr()
来源:互联网 发布:信义安所见乎翻译 编辑:程序博客网 时间:2024/05/16 03:19
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
翻译:手动实现strstr(字符串模式匹配 ---> KMP --->寻找next数组)
方法一:暴力求解,时间复杂度(O(mn))
class Solution(object): def strStr(self, haystack, needle): haystack_lenth = len(haystack) needle_lenth = len(needle) if(haystack_lenth == 0 and needle_lenth == 0): return 0 target_local = -1 for i in xrange(haystack_lenth): if i > (haystack_lenth - needle_lenth): break tmp_i = i match = 0 while(match < needle_lenth and tmp_i < haystack_lenth and haystack[tmp_i] == needle[match]): tmp_i += 1 match += 1 if(match == needle_lenth): target_local = i break return target_local
阅读全文
0 0
- [LeetCode]28.Implement strStr()
- LeetCode --- 28. Implement strStr()
- LeetCode 28.Implement strStr()
- [Leetcode] 28. Implement strStr()
- 28. Implement strStr()
- 【leetcode】28. Implement strStr()
- [leetcode] 28.Implement strStr()
- Leetcode-28.Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr() LeetCode
- 28. Implement strStr()
- leetcode 28. Implement strStr()
- [LeetCode]28. Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr()
- 28. Implement strStr()
- 2.3 图片类控件的使用
- Kotlin 中的操作符重载汇总表 与 可见性修饰符总结
- (组合数取模, 数论)2017"百度之星"程序设计大赛
- HTML中让段落自动空两格
- sc2017新高二&高一模拟赛5 总结
- 28. Implement strStr()
- 快捷键设置
- 关于类加载的一些分析总结
- Jenkins: Change Workspaces and Build Directory Locations
- 5043. 【NOI2017模拟4.4】保持平衡
- ssh项目中ajax与json之二级下拉菜单级联操作
- 51单片机实现时钟
- 15-SpringBoot——Spring MVC基础-服务端推送技术
- 20170813(两道题-dijkstra记录路径 BFS)