#include<iostream>
#include<string>
using namespace std;
class Solution{
public:
int implementStr(string haystack,string needle){
if(haystack.empty()|| needle.empty()){
return -1;
}
int len_hay = haystack.length();
int len_needle = needle.length();
if(len_hay < len_needle){
return -1;
}
int len_sub = len_hay - len_needle;
for(int i = 0; i <= len_sub ; i++){
bool flag = true;
for(int j = 0; j< len_needle; j++){
if (haystack[i+j] != needle[j]){
flag = false;
break;
}
}
if (flag){
return i;
}
}
return -1;
}
};
leetcode 28 Implement strStr()
最新推荐文章于 2019-09-08 17:47:58 发布