难度:简单
字符串轮转。给定两个字符串
s1
和s2
,请编写代码检查s2
是否为s1
旋转而成(比如,waterbottle
是erbottlewat
旋转后的字符串)。示例1:
输入:s1 = "waterbottle", s2 = "erbottlewat" 输出:True示例2:
输入:s1 = "aa", s2 = "aba" 输出:False提示:
- 字符串长度在[0, 100000]范围内。
说明:
- 你能只调用一次检查子串的方法吗?
题解:
class Solution(object): def isFlipedString(self, s1, s2): if len(s1) == 0 and len(s2) == 0: return True else: final_list = s1 + s1 if s2 in final_list and len(s2) == len(s1): return True return False
leetcode:面试题 01.09. 字符串轮转(python3解法)
![](https://img-home.csdnimg.cn/images/20240711042549.png)