1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-12-17 09:47:44 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/二进制反射排序 [sort-integers-by-binary-reflection].html
2025-12-17 09:38:38 +08:00

57 lines
2.1 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></p>
<p><strong>二进制反射</strong> 是对一个 <strong>正整数</strong> 的二进制表示按顺序反转(忽略前导零)后,将反转得到的二进制数转为十进制的结果。</p>
<p>请按每个元素的二进制反射值的 <strong>升序</strong> 对数组进行排序。如果两个不同的数字具有相同的二进制反射值,则 <strong>较小</strong> 的原始数字应排在前面。</p>
<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,5,4]</span></p>
<p><strong>输出:</strong> <span class="example-io">[4,4,5]</span></p>
<p><strong>解释:</strong></p>
<p>二进制反射值为:</p>
<ul>
<li>4 -&gt; (二进制) <code>100</code> -&gt; (反转) <code>001</code> -&gt; 1</li>
<li>5 -&gt; (二进制) <code>101</code> -&gt; (反转) <code>101</code> -&gt; 5</li>
<li>4 -&gt; (二进制) <code>100</code> -&gt; (反转) <code>001</code> -&gt; 1</li>
</ul>
根据反射值排序为 <code>[4, 4, 5]</code></div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [3,6,5,8]</span></p>
<p><strong>输出:</strong> <span class="example-io">[8,3,6,5]</span></p>
<p><strong>解释:</strong></p>
<p>二进制反射值为:</p>
<ul>
<li>3 -&gt; (二进制) <code>11</code> -&gt; (反转) <code>11</code> -&gt; 3</li>
<li>6 -&gt; (二进制) <code>110</code> -&gt; (反转) <code>011</code> -&gt; 3</li>
<li>5 -&gt; (二进制) <code>101</code> -&gt; (反转) <code>101</code> -&gt; 5</li>
<li>8 -&gt; (二进制) <code>1000</code> -&gt; (反转) <code>0001</code> -&gt; 1</li>
</ul>
根据反射值排序为 <code>[8, 3, 6, 5]</code><br />
注意3 和 6 的反射值相同,因此需要按原始值的升序排列。</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;= 10<sup>9</sup></code></li>
</ul>