Easy
Reverse an Array
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 15 min
- Arrays and Strings
Description
Given an array of integers, return a new array containing the same elements in reverse order.
The last element of the original array must become the first element of the result, and the first element must become the last. Preserve duplicate values and the original values exactly.
For example, reversing [1, 2, 3, 4] produces [4, 3, 2, 1].
Implement reverseArray(nums) to return the reversed array.
Constraints
1 <= nums.length <= 1000 -1000000 <= nums[i] <= 1000000 Return an array containing exactly nums.length elements.
Sample cases
3Sample 1
Input
nums = [1,2,3,4]
Expected output
[4,3,2,1]
Sample 2
Input
nums = [5]
Expected output
[5]
Skills and languages
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer