Skip to content

Commit 9ef46d6

Browse files
committed
Create README - LeetHub
1 parent c38eaa6 commit 9ef46d6

File tree

1 file changed

+54
-0
lines changed
  • 3769-sort-integers-by-binary-reflection

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<h2><a href="https://leetcode.com/problems/sort-integers-by-binary-reflection">4150. Sort Integers by Binary Reflection</a></h2><h3>Easy</h3><hr><p>You are given an integer array <code>nums</code>.</p>
2+
3+
<p>The <strong>binary reflection</strong> of a <strong>positive</strong> integer is defined as the number obtained by reversing the order of its <strong>binary</strong> digits (ignoring any leading zeros) and interpreting the resulting binary number as a decimal.</p>
4+
5+
<p>Sort the array in <strong>ascending</strong> order based on the binary reflection of each element. If two different numbers have the same binary reflection, the <strong>smaller</strong> original number should appear first.</p>
6+
7+
<p>Return the resulting sorted array.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
12+
<div class="example-block">
13+
<p><strong>Input:</strong> <span class="example-io">nums = [4,5,4]</span></p>
14+
15+
<p><strong>Output:</strong> <span class="example-io">[4,4,5]</span></p>
16+
17+
<p><strong>Explanation:</strong></p>
18+
19+
<p>Binary reflections are:</p>
20+
21+
<ul>
22+
<li>4 -&gt; (binary) <code>100</code> -&gt; (reversed) <code>001</code> -&gt; 1</li>
23+
<li>5 -&gt; (binary) <code>101</code> -&gt; (reversed) <code>101</code> -&gt; 5</li>
24+
<li>4 -&gt; (binary) <code>100</code> -&gt; (reversed) <code>001</code> -&gt; 1</li>
25+
</ul>
26+
Sorting by the reflected values gives <code>[4, 4, 5]</code>.</div>
27+
28+
<p><strong class="example">Example 2:</strong></p>
29+
30+
<div class="example-block">
31+
<p><strong>Input:</strong> <span class="example-io">nums = [3,6,5,8]</span></p>
32+
33+
<p><strong>Output:</strong> <span class="example-io">[8,3,6,5]</span></p>
34+
35+
<p><strong>Explanation:</strong></p>
36+
37+
<p>Binary reflections are:</p>
38+
39+
<ul>
40+
<li>3 -&gt; (binary) <code>11</code> -&gt; (reversed) <code>11</code> -&gt; 3</li>
41+
<li>6 -&gt; (binary) <code>110</code> -&gt; (reversed) <code>011</code> -&gt; 3</li>
42+
<li>5 -&gt; (binary) <code>101</code> -&gt; (reversed) <code>101</code> -&gt; 5</li>
43+
<li>8 -&gt; (binary) <code>1000</code> -&gt; (reversed) <code>0001</code> -&gt; 1</li>
44+
</ul>
45+
Sorting by the reflected values gives <code>[8, 3, 6, 5]</code>.<br />
46+
Note that 3 and 6 have the same reflection, so we arrange them in increasing order of original value.</div>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
53+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
54+
</ul>

0 commit comments

Comments
 (0)