Mid Coding

Check if a String is Rotation of Another String?

bool IsRotation(string s1, string s2)

if (s1.Length != s2.Length) return false;

string doubled = s1 + s1;

return doubled.Contains(s2);

Follow on:

Explanation:

If s2 is rotation of s1, it must be substring of s1+s1.

More from C# Programming Tutorial

All questions for this course