Skip to content

Commit ce51382

Browse files
committed
feat: rotate-string
1 parent e1b634b commit ce51382

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

str.rotate-string.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
"""
3+
796. 旋转字符串
4+
https://leetcode-cn.com/problems/rotate-string/
5+
给定两个字符串, A 和 B。
6+
A 的旋转操作就是将 A 最左边的字符移动到最右边。 例如, 若 A = 'abcde',在移动一次之后结果就是'bcdea' 。如果在若干次旋转操作之后,A 能变成B,那么返回True。
7+
"""
8+
def rotateString(self, A: str, B: str) -> bool:
9+
if len(A) != len(B):
10+
return False
11+
return (B * 2).find(A) != -1
12+
13+
14+
so = Solution()
15+
print(so.rotateString('abcde', 'abced'))

0 commit comments

Comments
 (0)