Skip to main content
459, Repeated Substring Pattern

I Problem

Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.

Example 1
Input: s = "abab"
Output: true
Explanation: It is the substring "ab" twice.


MikeAbout 1 minstringeasystringstring matching
28, Find the Index of the First Occurrence in a String

I Problem

Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Example 1
Input: haystack = "sadbutsad", needle = "sad"
Output: 0
Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0.


MikeAbout 2 minstringeasystringstring matchingtwo pointers
KamaCoder-55, Right-Rotated String

I Problem

The right rotation operation of a string is to transfer several characters at the end of the string to the front of the string. Given a string s and a positive integer k, please write a function to move the following k characters in the string to the front of the string, achieving the right rotation operation of the string.


MikeAbout 2 minstringeasystring
151, Reverse words in a String

I Problem

Given an input string s, reverse the order of the words.

A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.

Return a string of the words in reverse order concatenated by a single space.


MikeAbout 3 minstringmediumstringtwo pointers
KamaCoder-54, Replace Numbers

I Problem

Given a string s that contains lowercase alphabetic and numeric characters, write a function that leaves the alphabetic characters in the string unchanged and replaces each numeric character with a number. For example, for the input string "a1b2c3", the function should convert it to "anumberbnumbercnumber".


MikeLess than 1 minutestringeasystring
541, Reverse String II

I Problem

Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.

  • If there are fewer than k characters left, reverse all of them.
  • If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and leave the other as original.

MikeLess than 1 minutestringeasystringtwo pointers
344, Reverse String

I Problem

Write a function that reverses a string. The input string is given as an array of characters s.

You must do this by modifying the input array in-place with O(1) extra memory.


MikeLess than 1 minutestringeasystringtwo pointers