算法笔记: 力扣#796 旋转字符串

问题描述


解法


分析

Python 实现

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 实现

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

时间复杂度

O(N^2).

空间复杂度

O(N).

链接


796. Rotate String
796. 旋转字符串
(English version) Algorithm Notes: Leetcode#796 Rotate String