mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
@ -425,8 +425,8 @@ public:
|
||||
if (needle.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
int next[needle.size()];
|
||||
getNext(next, needle);
|
||||
vector<int> next(needle.size());
|
||||
getNext(&next[0], needle);
|
||||
int j = -1; // // 因为next数组里记录的起始位置为-1
|
||||
for (int i = 0; i < haystack.size(); i++) { // 注意i就从0开始
|
||||
while(j >= 0 && haystack[i] != needle[j + 1]) { // 不匹配
|
||||
@ -524,8 +524,8 @@ public:
|
||||
if (needle.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
int next[needle.size()];
|
||||
getNext(next, needle);
|
||||
vector<int> next(needle.size());
|
||||
getNext(&next[0], needle);
|
||||
int j = 0;
|
||||
for (int i = 0; i < haystack.size(); i++) {
|
||||
while(j > 0 && haystack[i] != needle[j]) {
|
||||
@ -1428,4 +1428,3 @@ public int[] GetNext(string needle)
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
Reference in New Issue
Block a user