Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean checkStringRotation(String string1, String string2) {
- /* Length of string1 */
- int n = string1.length();
- /* Length of the strings are not same - Not a rotation */
- if (n != string2.length())
- return false;
- int i = 0;
- int j = 0;
- while (i < (n - 1) && j < (n - 1)) {
- int k = 1;
- while (k <= n && string1.charAt((i + k) % n) == string2.charAt((j + k) % n))
- k++;
- if (k > n)
- return true;
- if (string1.charAt((i + k) % n) > string2.charAt((j + k) % n))
- i += k;
- else
- j += k;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement