Given an integer array nums of size n, reverse the elements of the array in-place, without using any extra space.

Write a function reverseArray that takes in an integer array nums and modifies it to reverse the order of its elements.

You can assume that nums will always have at least one element.

Input:

  • An integer array nums of size n (1 ≤ n ≤ 10^4) where each element is an integer (-10^9 ≤ nums[i] ≤ 10^9).

Output:

  • The input array nums should be modified in-place to reverse the order of its elements.

Example 1:

Input: nums = [4, 2, 5, 1, 6, 3]
Output: [3, 6, 1, 5, 2, 4]
Explanation: After reversing the elements of the array in-place, the modified array is [3, 6, 1, 5, 2, 4].

Example 2:

Input: nums = [1, 5, 7, 2, 9, 3]
Output: [3, 9, 2, 7, 5, 1]
Explanation: After reversing the elements of the array in-place, the modified array is [3, 9, 2, 7, 5, 1].
Comments (5)