Given a string ans a specified character, reverse the prefix that is ended with the specified character.
Intuition
Simulate the process.
Approach
find the first occurrence of the specified character, then reverse the prefix.
Complexity
Time complexity: find the first occurrence of the specified character. $$O(n)$$
Space complexity: no extra spaces are needed. $$O(1)$$
Code
|
|