357. Reverse a String II

Given a string, the task is to reverse it. The string is represented by an array of characters s.

Perform the reversal in place with O(1) extra memory.

Note: no need to return anything, modify the given list.

Example 1:

Input : s = ["h", "e" ,"l" ,"l" ,"o"]

Output : ["o", "l", "l", "e", "h"]

Explanation :

The given string is s = "hello" and after reversing it becomes s = "olleh".

Example 2:

Input : s = ["b", "y" ,"e" ]

Output : ["e", "y", "b"]

Explanation :

The given string is s = "bye" and after reversing it becomes s = "eyb".

Now Your Turn!

Pick the correct output for the given input

Input : s = ["h", "a" ,"n" ,"n" ,"a", "h"]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s consist of only lowercase and uppercase English characters.
0
class Solution{
public:
void reverseString(vector<char>& s){
//your code goes here
}
};
Test Case

Input:

S