How LeetCode adjusts the array order so that odd numbers precede even numbers
This article mainly introduces how LeetCode adjusts the array order so that odd numbers are located in front of even numbers. The article is very detailed and has certain reference value. Interested friends must read it!
Input an array of integers, implement a function to adjust the order of the numbers in the array, so that all odd numbers are located in the first half of the array, all even numbers are located in the second half of the array, and ensure that the relative position between odd and odd, even and even numbers remains unchanged.
Idea 1: Create two arrays to store odd and even numbers respectively, odd numbers enter v1, even numbers enter v2, and finally merge
Code:
void reOrderArray(vector &array){ vector v1; vector v2; for(int i=0;i