Given a 0-indexed string
word
and a characterch
, reverse the segment ofword
that starts at index0
and ends at the index of the first occurrence ofch
(inclusive). If the characterch
does not exist inword
, 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.
1 | class Solution { |