/344. Reverse String

344. Reverse String

Easy
Two Pointers80.6% acceptance

Given a list of characters named char_list, reverse the elements of char_list in-place. You must modify the input list directly using O(1) extra memory.

Example 1

Input: [a, b, c, d]

Output: [d, c, b, a]

Explanation: The list is reversed in-place.

Example 2

Input: [X, Y, Z]

Output: [Z, Y, X]

Explanation: The list is reversed in-place.

Constraints

  • 1 <= len(char_list) <= 105
  • Each element in char_list is a printable ASCII character
Python (current runtime)

Case 1

Input: ['q', 'w', 'e', 'r', 't', 'y']

Expected: ['y', 't', 'r', 'e', 'w', 'q']

Case 2

Input: ['1', '2', '3', '4', '5']

Expected: ['5', '4', '3', '2', '1']

Case 3

Input: ['A', 'B']

Expected: ['B', 'A']

Case 4

Input: ['!']

Expected: ['!']