2000. Reverse Prefix of Word
https://leetcode.com/problems/reverse-prefix-of-word
Description
Given a 0-indexed string word
and a character ch
, reverse the segment of word
that starts at index 0
and ends at the index of the first occurrence of ch
(inclusive). If the character ch
does not exist in word
, do nothing.
For example, if
word = "abcdefd"
andch = "d"
, then you should reverse the segment that starts at0
and ends at3
(inclusive). The resulting string will be"dcbaefd"
.
Return the resulting string.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= word.length <= 250
word
consists of lowercase English letters.ch
is a lowercase English letter.
ac
Previous1999. Smallest Greater Multiple Made of Two DigitsNext2001. Number of Pairs of Interchangeable Rectangles
Last updated