Partição de pares e ímpares
Escreva uma função que divida o array em dois subarrays: um com todos os números inteiros pares e outro com todos os ímpares. Retorne o resultado no seguinte formato:
[[evens], [odds]]Exemplos
Program.EvenOddPartition(new int[] { 5, 8, 9, 2, 0 }) ➞ new int[][] { new int[] { 8, 2, 0 }, new int[] { 5, 9 } }
Program.EvenOddPartition(new int[] { 1, 0, 1, 0, 1, 0 }) ➞ new int[][] { new int[] { 0, 0, 0 }, new int[] { 1, 1, 1 } }
Program.EvenOddPartition(new int[] { 1, 3, 5, 7, 9 }) ➞ new int[][] { new int[] { }, new int[] { 1, 3, 5, 7, 9 } }
Program.EvenOddPartition(new int[] { }) ➞ new int[][] { new int[] { }, new int[] { } }Notas
- Se o array de entrada estiver vazio, retorne dois subarrays vazios.
- Mantenha a mesma ordem relativa dos elementos do array original.