题目
We are given two strings, A and B.
A shift on A consists of taking string A and moving the leftmost character to the rightmost position. For example, if A = 'abcde', then it will be 'bcdea' after one shift on A. Return True if and only if A can become B after some number of shifts on A.
答案
Example
before rotate: s: "abcde"
after rotate: cdeab (right substring of s + left substring of s)
If we concatenate s twice, i.e: ss = s + s = abcdeabcde
the string after rotation will show up in ss
class Solution {
public boolean rotateString(String A, String B) {
String AA = A + A;
return A.length() == B.length() && AA.contains(B);
}
}