1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/按奇偶排序数组 II [sort-array-by-parity-ii].html
2022-03-29 12:43:11 +08:00

38 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个非负整数数组&nbsp;<code>nums</code>&nbsp;&nbsp;<code>nums</code> 中一半整数是 <strong>奇数</strong> ,一半整数是 <strong>偶数</strong></p>
<p>对数组进行排序,以便当&nbsp;<code>nums[i]</code> 为奇数时,<code>i</code>&nbsp;也是 <strong>奇数</strong> ;当&nbsp;<code>nums[i]</code>&nbsp;为偶数时, <code>i</code> 也是 <strong>偶数</strong></p>
<p>你可以返回 <em>任何满足上述条件的数组作为答案</em></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [4,2,5,7]
<strong>输出:</strong>[4,5,2,7]
<strong>解释:</strong>[4,7,2,5][2,5,4,7][2,7,4,5] 也会被接受。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [2,3]
<b>输出:</b>[2,3]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>nums.length</code>&nbsp;是偶数</li>
<li><code>nums</code>&nbsp;中一半是偶数</li>
<li><code>0 &lt;= nums[i] &lt;= 1000</code></li>
</ul>
<p>&nbsp;</p>
<p><strong>进阶:</strong>可以不使用额外空间解决问题吗?</p>