Rotate String

Problem

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.

Solution

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

Recent posts from blogs that I like

What to do when a macOS update goes wrong

Anything can happen, but so long as you have a recent backup you should be able fix the problems and get back up and running again. Here's how.

via The Eclectic Light Company

no two things the same

Tony Feher, Come Out and Play Stephen Jay (detail), 2013

via bookbear express

Microsoft Plugs Nearly 400 Security Holes

Microsoft today released updates to remedy at least 398 security vulnerabilities in its Windows operating systems and supported software, including one weakness that is already being actively exploited and two others that were publicly detailed prior to today.

via Krebs on Security