Monday, 4 June 2012

A Program to check if strings are rotations of each other or not

Solution:

If the two given strings are A,B;
concatenate A+A => S.
Now if S contains B, then A is a rotation of B, else not.

Using KMP this can be done in O(n).

http://www.geeksforgeeks.org/archives/429

No comments:

Post a Comment