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.
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.
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
.
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.
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.
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"
.
Given a string s
and an integer k
, reverse the first k
characters for every 2k
characters counting from the start of the string.
k
characters left, reverse all of them.2k
but greater than or equal to k
characters, then reverse the first k
characters and leave the other as original.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.