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

Masaccio’s six years

His first painting as a Master in his own right was in 1422. He built depth and realism into faces and figures, and mastered 3D perspective projection, then 6 years later vanished in Rome, reported dead.

via The Eclectic Light Company

AI is driving a boom in modestly successful software projects

If AI is so great, why aren’t we seeing an explosion of new, amazing software products? If anyone can turn their idea into working software with coding agents, where is all that software? People have been asking this question for years. As far as I can tell, the answer is that it’s spread out over a...

via Sean Goedecke

How is music possible

If you take a scene from a horror movie and add funny music, the killer suddenly looks hilarious. Isn’t it strange that that happens?

via Henrik Karlsson