algorithm notes: leetcode#796 rotate string

Problem


Solution


Analysis

Python implementation

1
2
3
4
5
6
7
8
class :
def rotateString(self, A, B):
"""
:type A: str
:type B: str
:rtype: bool
"""
return len(A) == len(B) and A in B+B

Java implementation

1
2
3
4
5
class {
public boolean rotateString(String A, String B) {
return A.length() == B.length() && (B+B).contains(A);
}
}

Time complexity

O(N^2).

Space complexity

o(N).


796. Rotate String
(中文版) 算法笔记: 力扣#796 旋转字符串