1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-09 09:21:40 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/将数组按照奇偶性转化 [transform-array-by-parity].html
2025-03-14 03:44:12 +08:00

51 lines
1.6 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>给你一个整数数组 <code>nums</code>。请你按照以下顺序 <strong>依次</strong>&nbsp;执行操作,转换 <code>nums</code></p>
<ol>
<li>将每个偶数替换为 0。</li>
<li>将每个奇数替换为 1。</li>
<li>&nbsp;<strong>非递减&nbsp;</strong>顺序排序修改后的数组。</li>
</ol>
<p>执行完这些操作后,返回结果数组。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1:</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [4,3,2,1]</span></p>
<p><strong>输出:</strong><span class="example-io">[0,0,1,1]</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>将偶数4 和 2替换为 0将奇数3 和 1替换为 1。现在<code>nums = [0, 1, 0, 1]</code></li>
<li>按非递减顺序排序 <code>nums</code>,得到 <code>nums = [0, 0, 1, 1]</code></li>
</ul>
</div>
<p><strong class="example">示例 2:</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [1,5,1,4,2]</span></p>
<p><strong>输出:</strong><span class="example-io">[0,0,1,1,1]</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>将偶数4 和 2替换为 0将奇数1, 5 和 1替换为 1。现在<code>nums = [1, 1, 1, 0, 0]</code></li>
<li>按非递减顺序排序&nbsp;<code>nums</code>,得到 <code>nums = [0, 0, 1, 1, 1]</code></li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>1 &lt;= nums[i] &lt;= 1000</code></li>
</ul>