Search for a command to run...
You are given an integer array nums.
Your task is to reverse the order of elements in the array in-place.
You must modify the original array directly without creating another array for the result.
O(n) time complexity
O(1) extra space complexity
An integer array nums
Return the modified array after reversing its elements.
nums = [1, 2, 3, 4, 5, 6][6, 5, 4, 3, 2, 1]The array is reversed in-place by swapping elements from both ends.
1 ≤ nums.length ≤ 10^5
-10^9 ≤ nums[i] ≤ 10^9
Example 1
[1,2,3,4,5,6][6,5,4,3,2,1][1,2,3,4,5,6]
[6,5,4,3,2,1]