JIAKAOBO

LeetCode

venmo
wechat

感谢赞助!

  • ㊗️
  • 大家
  • offer
  • 多多!

Problem

We are given two strings, s and goal.

A shift on s consists of taking string s and moving the leftmost character to the rightmost position. For example, if s = ‘abcde’, then it will be ‘bcdea’ after one shift on s. Return true if and only if s can become goal after some number of shifts on s.

Example 1:

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

Example 2:

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

Code

class Solution {
    public boolean rotateString(String s, String goal) {
        return s.length() == goal.length() && (s + s).contains(goal);
    }
}