Leetcode 796 Rotate String
Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.
A shift on s consists of moving the leftmost character of s to the rightmost position.
- For example, if s = “abcde”, then it will be “bcdea” after one shift.
Input: s = "abcde", goal = "cdeab"
Output: true
Input: s = "abcde", goal = "abced"
Output: false
- All rotations of A are contained in A+A. Thus, we can simply check whether B is a substring of A+A. We also need to check A.length == B.length, otherwise we will fail cases like A = “a”, B = “aa”.
class Solution(object):
def rotateString(self, A, B):
return len(A) == len(B) and B in A+A