Solution Review: Remove Even Integers From an Array
This review provides a detailed analysis of solving the "Remove Even Integers From an Array" challenge.
We'll cover the following...
Solution #
Press + to interact
namespace chapter_2{class Solution{static int [] removeEven(int[]Arr, int size){int m = 0;for (int i = 0; i < size; i++){if (Arr[i] % 2 != 0) // if odd number found{Arr[m] = Arr[i]; //inserting odd values in the array++m;}}int[] temp = new int[m];for (int i = 0; i < m; i++)temp[i] = Arr[i];Arr = temp;return Arr; // returning the array after removing the odd numbers}//Remove Event Integers from an Array:static void Main(string[] args){int[] arr = null; // declaring arrayarr = new int[10]; // memory allocationConsole.Write("Before remove even: ");for (int i = 0; i < 10; i++){arr[i] = i; // assigning valuesConsole.Write(arr[i] + " ");}Console.WriteLine("");arr = removeEven(arr, 10); // calling removeEvenConsole.Write("After remove even: ");for (int i = 0; i < 5; i++){Console.Write( arr[i] + " "); // prinitng array}Console.WriteLine("");return ;}}}
Explanation
This solution starts with the first element of the given array: Arr
checks if it is odd. Then it moves this element to the start of the array Arr
...