#344

Reverse String

newbie · 175 · lc easy +15 · verified · 80.6% accepted · 9,518 likes · top 92%

play →

Description

Reverse the character array s in-place, swapping characters from both ends toward the center, using only O(1) additional memory.

Example 1:

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

Example 2:

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

Code

1
2
3
4
5
6