Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to sort arrays by parity in leetCode

Shulou Source: shulou.com Published: 2022-06-02 05:29:44 10月02日 Update

LeetCode in how to sort the array by parity, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

First, sort the array II1 by parity, a brief description of the problem.

Given a non-negative integer array A, half of the integers in An are odd and half of the integers are even.

Sort the array so that when A [I] is odd, I is also odd; when A [I] is even, I is even.

You can return any array that meets the above criteria as an answer.

2. Example description example:

Input: [4, 2, 5, 7]

Output: [4, 5, 5, 2, 7]

Explanation: [4, 7, 2, 5], [2, 5, 5, 4, 7], [2, 7, 4, 5] will also be accepted.

Tip:

two

Tags: Arrays sorting even odd integers parity examples problem solutions help clarity location content this ideas articles novices more conditions knowledge programs Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info macOS Microsoft Shulou Technology