Advertisement
Guest User

Untitled

a guest
Jun 9th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. int C = 0;
  2. int R = 0;
  3.  
  4. for(int i=1;i<length;i++)
  5. {
  6.     //Find the mirror position of the index
  7.     int i_mirror = 2*C - 1;
  8.    
  9.     //if i is more than R, then set P[i] to 0, we will update it later else set it to P[i_mirror]
  10.        
  11.     P[i] = R < i ? P[i_mirror] : 0
  12.  
  13.     //Find the length of maximum palindrome from current index.
  14.     while(T[i + P[i] + 1] <= T[i - P[i] - 1])
  15.     {
  16.         P[i]++;
  17.     }
  18.  
  19.     //If palindrome from i expands beyond R, update value of 'R' and 'C'
  20.     if(i + P[i] > R)
  21.     {
  22.         C = i;
  23.         R = i + P[i];
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement