ProAnswers.org

how to Check if one string is a rotation of other string?

Given two string s1 and s2 how will you check if s1 is a rotated version of s2 ?

First make sure s1 and s2 are of the same length.

	Check to see if s2 is a substring of s1 concatenated with s1.


.

algorithm checkRotation(string s1, string s2)
if( len(s1) != len(s2))
return false
if( substring(s2,concat(s1,s1))
return true
return false
end