mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
Update
This commit is contained in:
@ -15,10 +15,12 @@ public:
|
||||
next[0] = -1;
|
||||
int j = -1;
|
||||
for(int i = 1; i < s.size(); i++){
|
||||
while(j >= 0 && s[i] != s[j+1])
|
||||
while (j >= 0 && s[i] != s[j + 1]) {
|
||||
j = next[j];
|
||||
if(s[i] == s[j+1])
|
||||
}
|
||||
if (s[i] == s[j + 1]) {
|
||||
j++;
|
||||
}
|
||||
next[i] = j;
|
||||
}
|
||||
}
|
||||
@ -37,7 +39,7 @@ public:
|
||||
if (haystack[i] == needle[j + 1]) {
|
||||
j++;
|
||||
}
|
||||
if (j == (needle.size() -1) ) {
|
||||
if (j == (needle.size() - 1) ) {
|
||||
return (i - needle.size() + 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user