Skip to content

Instantly share code, notes, and snippets.

@GeekaholicLin
Last active June 11, 2016 03:07
Show Gist options
  • Save GeekaholicLin/e62197527f1b1cbca366b36f8a65f68c to your computer and use it in GitHub Desktop.
Save GeekaholicLin/e62197527f1b1cbca366b36f8a65f68c to your computer and use it in GitHub Desktop.
字符串朴素匹配中的指针回溯

最近脑子有点转不过来,不清楚字符串朴素匹配算法中的指针回溯是怎么算来的 即 i=j-i+2;j=1; 是怎么得来的。 当不匹配时,子串下标回到j=1,而父串下标则相对之前的i而言,要+1,回到下一个需要匹配的字符。 可以这么认为,j从1到j,增加了(j-1),当i需要从现在的i回到需要匹配的下一个字符,自然要 i=i-(j-1)+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment