再写String indexOf KMP算法
来源:互联网 发布:php 生成订单号 编辑:程序博客网 时间:2024/06/19 01:13
class Solution { /** * Returns a index to the first occurrence of target in source, * or -1 if target is not part of source. * @param source string to be scanned. * @param target string containing the sequence of characters to match. */ public int strStr(String source, String target) { //write your code here if(source == null || target == null) return -1; if(target.length() == 0) return 0; int[] next = new int[target.length()]; int m = 0, n = -1; next[0] = -1; while(m < target.length() - 1) { if(n == -1 || target.charAt(m) == target.charAt(n)) { m++; n++; next[m] = n; } else { n = next[n]; } } int i = 0, j = 0; while(j < target.length() && i < source.length()) { if(j == -1 || source.charAt(i) == target.charAt(j)) { i++; j++; } else { j = next[j]; } } if(j == target.length()) return i - j; return -1; }}
0 0
- 再写String indexOf KMP算法
- String indexOf 算法
- 为什么JDK中String类的indexof不使用KMP或者Boyer-Moore等时间复杂度低的算法编辑器
- power string kmp算法
- string KMP算法理解
- KMP算法 c++ string
- String.IndexOf
- String.IndexOf()
- String.indexof
- indexOf(String.indexOf 方法)
- indexOf(String.indexOf 方法)
- indexOf(String.indexOf 方法)
- indexOf(String.indexOf 方法)
- indexOf(String.indexOf 方法)
- indexOf(String.indexOf 方法)
- indexOf(String.indexOf 方法)
- indexOf(String.indexOf 方法)
- (KMP算法)Power String(P2406)
- Leetcode NO.293 Flip Game
- 数据结构例程——二叉树的构造
- 数据结构例程——线索化二叉树(中序)
- Leetcode NO.266 Palindrome Permutation
- 数据结构例程——哈夫曼树
- 再写String indexOf KMP算法
- Hadoop学习笔记(一)
- oracle-function-lag-lead
- PHP的语言结构和函数的区别
- 在linux下用源代码编译MPICH 3.1.4
- IOS开发笔记-01按钮操作-13.上下左右移动 14.代码优化
- 数据挖掘工程师笔试及答案整理
- c语言之 switch 和 if 的使用比较(一)
- BZOJ 1512 [POI2006]Pro-Professor Szu Tarjan缩点+拓扑DP