public bool IsRotatedString(string s1, string s2) { int length = s1.Length; if (length == s2.Length && length > 0) { StringSearcher searcher = new StringSearcher(); string s1s1 = s1 + s1; return(searcher.CountSubstringInstances(s2, s1s1) > 0); } return(false); }
public bool IsRotatedString(string s1, string s2) { if (s1.Length != s2.Length) { return(false); } int index = 0; for (int i = 0; i < s2.Length; i++) { if (i == 0) { for (int j = 0; j < s1.Length; j++) { if (s1[j] == s2[i]) { index = j; break; } } return(false); } if (s1[index] != s2[i]) { if (s1[0] == s2[i]) { StringSearcher searcher = new StringSearcher(); string sub = BuildTailingSubstring(s2, i); return(searcher.CountSubstringInstances(s2, sub) > 0); } return(false); } index++; if (index > s1.Length) { return(false); } } return(false); }