Suppose we have two strings s and t, we have to check whether t is a rotation of s or not.
So, if the input is like s = "hello", t = "llohe", then the output will be True.
To solve this, we will follow these steps −
- if size of s is not same as size of t, then
- return False
- temp := s concatenate with s again
- if count of t in temp > 0, then
- return True
- return False
Let us see the following implementation to get better understanding −
Example Code
def solve(s, t): if len(s) != len(t): return False temp = s + s if temp.count(t)> 0: return True return False s = "hello" t = "llohe" print(solve(s, t))
Input
"hello", "llohe"
Output
True