
暴力匹配
class Solution {public int strStr(String haystack, String needle) {int sLen = haystack.length();// 主字符串int pLen = needle.length();// 模式串长度// 需要匹配的次数for (int i=0;i<=sLen-pLen;i++){int j ;// 遍历模式串for (j=0;j<pLen;j++){if (needle.charAt(j)!=haystack.charAt(i+j)){break;}}// 如果j移动到模板末尾了 说明匹配成功了if (j==pLen) return i ;}return -1;}}
