Skip to content

796. Rotate String 👍

  • Time: $O(|\texttt{A}|^2)$
  • Space: $O(1)$
1
2
3
4
5
6
class Solution {
 public:
  bool rotateString(string A, string B) {
    return A.length() == B.length() && (A + A).find(B) != string::npos;
  }
};
1
2
3
4
5
class Solution {
  public boolean rotateString(String A, String B) {
    return A.length() == B.length() && (A + A).contains(B);
  }
}
Back to top