Guest User

Untitled

a guest
May 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. private int[] pre_kmp(String x)
  2. {
  3. int i, j;
  4. int m = x.length()-1;
  5. int kmp_next[] = new int[m+1];
  6.  
  7. i = 0;
  8. j = -1;
  9. kmp_next[0] = -1;
  10. while (i < m)
  11. {
  12. while (j > -1 && x.charAt(i) != x.charAt(j))
  13. j = kmp_next[j];
  14. i++;
  15. j++;
  16. if (x.charAt(i) == x.charAt(j))
  17. kmp_next[i] = kmp_next[j];
  18. else
  19. kmp_next[i] = j;
  20. }
  21. return kmp_next;
  22. }
Add Comment
Please, Sign In to add comment