Sort Array as Odd numbers followed by Even numbers in Java | Sort array as store All even numbers first and all Odd numbers last. Given an array of non-negative integers, return an array consisting of all the even elements of array followed by all the odd elements of array. You may return any answer array that satisfies this condition. Example 1 :- Input: [3,1,2,4] Output: [2,4,3,1] The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted. See description in Leetcode :- Sort Array By Parity So lets see solution of above problem. Solution 1 : In place with For loop class Solution { public int[] sortArrayByParity(int[] array) { if (array.length > 1) { int rightIndex = array.length - 1; for (int leftIndex = 0; leftIndex < array.length;) { ...
Welcome To Programming Tutorial. Here i share about Java Programming stuff. I share Java stuff with simple examples.