Leetcode One Question of the Day 2020.11.12 Question 922: Sort the array by parity Ⅱ

922. Sort array by parity Ⅱ

Title description

Insert picture description here
Insert picture description here

Ideas, algorithms and code implementation

Method 1: Define two empty lists odd[] and even[] to store odd and even numbers respectively, and then put the numbers in odd[] and even[] into the result list res[] in turn.
Insert picture description here
Method 2: Define two empty lists odd[] and even[] to store the element position indexes of A[] that should be odd and even, and finally exchange odd and even numbers.
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_51210480/article/details/109748308