Inversão de um trecho
Escreva uma função que inverta o trecho do array entre os índices inicial e final (incluindo ambos os índices). O restante do array deve permanecer igual.
Exemplos
Program.rangedReversal(new int[]{1, 2, 3, 4, 5, 6}, 1, 3) ➞ new int[]{1, 4, 3, 2, 5, 6}
Program.rangedReversal(new int[]{1, 2, 3, 4, 5, 6}, 0, 4) ➞ new int[]{5, 4, 3, 2, 1, 6}
Program.rangedReversal(new int[]{9, 8, 7, 4}, 0, 0) ➞ new int[]{9, 8, 7, 4}Notas
- Os índices dos arrays começam em zero.
- Os índices inicial e final sempre serão válidos para o array.
- O índice final sempre será maior ou igual ao índice inicial.
- Retorne o próprio array se os índices inicial e final forem iguais.