Talentd
FleetCode

796. Rotate String

Easy66.6% acceptance12 companies

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.

Example 1:

Input: s = "abcde", goal = "cdeab"
Output: true

Example 2:

Input: s = "abcde", goal = "abced"
Output: false

Constraints:

  • 1 <= s.length, goal.length <= 100
  • s and goal consist of lowercase English letters.
16:46
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def rotateString(self, s: str, goal: str) -> bool:
3
Starter codePython 3Spaces: 4
Examples
Input
"abcde"
"cdeab"
Input
"abcde"
"abced"
Your code is saved on this device.Solution