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
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