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

38 lines
1.2 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<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>