字符串旋转:
给定两字符串A和B,如果能将A从中间某个位置分割为左右两部分字符串(可以为空串),并将左边的字符串移动到右边字符串后面组成新的字符串可以变为字符串B时返回true。
Python
class Solution:
def solve(self , A: str, B: str) -> bool:
if len(A) != len(B): return False
for i in range(len(A)):
if A[i:] + A[:i] == B: return True
return False
- 如果
B
是AA
的子串,则返回True
;
Python
class Solution:
def solve(self , A: str, B: str) -> bool:
if len(A) != len(B): return False
return B in A + A