Warm-ups · 4 of 24
Reverse an array in place
Reverse the array without creating a new one. Change nums itself; return nothing.
Examples
Input nums = [1, 2, 3, 4]
Output nums becomes [4, 3, 2, 1]
Input nums = [1, 2, 3]
Output nums becomes [3, 2, 1]
The middle element stays where it is.
📘 New to this? Two pointers from opposite ends explains the idea in a few minutes.
Solved it? The same idea on LeetCode: try it there ↗