← 返回 meta 的题目列表Reverse Elements in Array
类型:online_judge
meta
Given an integer array array and two indices i and j, reverse the elements between i and j. Be sure to handle edge cases such as i being greater than j, array being null, i and j out of boundaries.
Input
An integer array array.
Two integer indices i and j.
Output
The modified array with elements between indices i and j reversed.
Example
Input: array = [1, 2, 3, 4, 5], i = 1, j = 3
Output: [1, 4, 3, 2, 5]
Input: array = [1, 2, 3], i = 0, j = 0
Output: [1, 2, 3]
Input: array = [1, 2, 3], i = 3, j = 1
Output: [1, 2, 3]
Constraints
0 <= i, j < array.length
Example
Input
[1, 2, 3, 4, 5]
1
3