#C2114. Check for String Rotation
Check for String Rotation
Check for String Rotation
Given two non-empty strings s1
and s2
, determine if s2
is a rotation of s1
. A string s2
is considered a rotation of s1
if there exist two non-empty substrings \(A\) and \(B\) such that \(s1 = A + B\) and \(s2 = B + A\). Note that if either string is empty or the strings have different lengths, then s2
is not a rotation of s1
.
Example:
- If
s1 = "waterbottle"
ands2 = "erbottlewat"
, then the answer isTrue
(as we can splits1
into "water" and "bottle"). - If
s1 = "hello"
ands2 = "lloeh"
, then the answer isFalse
.
inputFormat
The input consists of two lines:
- The first line contains the string
s1
. - The second line contains the string
s2
.
outputFormat
Output a single line: True
if s2
is a rotation of s1
; otherwise, output False
.
abcde
abcde
True