string rotation (if string is the rotate of the other)

ex: ABCD -> CDAB or DABC


If str1 is the substring of str2 concatenated with itself(str2), then it is the rotation of it

boolean isRotation(String s1,String s2) {
    return (s1.length() == s2.length()) && ((s1+s1).indexOf(s2) != -1);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章