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

taiwan travelogue

a review

via bookbear express

William Merritt Chase and the independence of American painting 1

How the teaching of art, especially that of William Merritt Chase, brought artistic independence to the USA in the late 19th century, painters from Lydia Field Emmet to Louise Upton Brumback.

via The Eclectic Light Company

Overtraining as the path to human-like AI

The anonymous blogger Gwern recently completed a thirteen thousand word post called Human-like Neural Nets by Catapulting, in which he offers a theory about why LLMs don’t possess truly flexible human-like intelligence, and how we might train LLMs that do. Theories like this are entirely unremarkabl...

via Sean Goedecke