Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int C = 0;
- int R = 0;
- for(int i=1;i<length;i++)
- {
- //Find the mirror position of the index
- int i_mirror = 2*C - 1;
- //if i is more than R, then set P[i] to 0, we will update it later else set it to P[i_mirror]
- P[i] = R < i ? P[i_mirror] : 0
- //Find the length of maximum palindrome from current index.
- while(T[i + P[i] + 1] <= T[i - P[i] - 1])
- {
- P[i]++;
- }
- //If palindrome from i expands beyond R, update value of 'R' and 'C'
- if(i + P[i] > R)
- {
- C = i;
- R = i + P[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement