Leetcode28,实现strstr
sunday算法
1、建立next数组,代表每个字母,在pattern数组中最后一次出现的下标位置
2、起始位置i,进行匹配是否满足要求;满足就返回起始位置i;不满足需要移动起始位置
3、i的下个位置跳跃为:i += pattern - next[haystack[pattern+i]];
处理过程中,请注意保证每个下标都是有效的
举例1
举例2
class Solution {
public:
int strStr(string haystack, string needle) {
int i, j, patternlen, len;
patternlen = needle