LeetCode Solutions

796. Rotate String

Time: $O(|\texttt{A}|^2)$

Space: $O(1)$

			

class Solution {
 public:
  bool rotateString(string A, string B) {
    return A.length() == B.length() && (A + A).find(B) != string::npos;
  }
};
			

class Solution {
  public boolean rotateString(String A, String B) {
    return A.length() == B.length() && (A + A).contains(B);
  }
}