All problems

Reverse String

Easy · two pointers

You are given a list of characters s. Return a new list that holds the same characters in reverse order: the first character of s becomes the last, the second becomes the second to last, and so on.

Do not change s itself; just build and return the reversed list. A list of one character is its own reverse.

Examples

Example 1

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

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

Example 2

Input: s = ["a", "b", "c", "d"]

Output: ["d", "c", "b", "a"]

With an even number of characters, every character swaps places with another one.

Example 3

Input: s = ["x"]

Output: ["x"]

Constraints