ปัญหา
ให้สตริง s และ t ตรวจสอบว่า t เป็นการหมุนเวียนของ s หรือไม่
ตัวอย่าง
s = "hello", t = "llohe" → t อยู่ใน s+s = "hellohello" → True
แนวคิดการแก้ปัญหา
- ถ้าความยาวต่างกัน → False
- เช็คว่า t เป็น substring ของ s+s
โค้ดตัวอย่าง
def solve(s, t):
if len(s) != len(t):
return False
return t in (s + s)
print(solve("hello", "llohe")) # True
อินพุต / เอาต์พุต
Input: "hello", "llohe" Output: True