Advertisement
Semior001

palindromes

Dec 10th, 2016
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. // дана строка s и её длина n
  2. int d[1000001];
  3.  
  4. l = 0;
  5. r = 0;
  6. for(int i = 0; i < n; i++){
  7.     if(i<=r){
  8.         d[i] = min(d[l+r-i],r-i+1);
  9.     }
  10.     while(i - d[i] >= 0 &&
  11.           i + d[i] < n &&
  12.           s[i - d[i]] == s[i + d[i]]){
  13.         d[i]++;
  14.     }
  15.     if(r < i + d[i] - 1){
  16.         l = i - d[i] + 1;
  17.         r = i + d[i] - 1;
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement