Skip to content

Commit 332226c

Browse files
committed
Create README - LeetHub
1 parent bceb3c7 commit 332226c

File tree

1 file changed

+41
-0
lines changed
  • 3750-minimum-number-of-flips-to-reverse-binary-string

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<h2><a href="https://leetcode.com/problems/minimum-number-of-flips-to-reverse-binary-string">4126. Minimum Number of Flips to Reverse Binary String</a></h2><h3>Easy</h3><hr><p>You are given a <strong>positive</strong> integer <code>n</code>.</p>
2+
3+
<p>Let <code>s</code> be the <strong>binary representation</strong> of <code>n</code> without leading zeros.</p>
4+
5+
<p>The <strong>reverse</strong> of a binary string <code>s</code> is obtained by writing the characters of <code>s</code> in the opposite order.</p>
6+
7+
<p>You may flip any bit in <code>s</code> (change <code>0 &rarr; 1</code> or <code>1 &rarr; 0</code>). Each flip affects <strong>exactly</strong> one bit.</p>
8+
9+
<p>Return the <strong>minimum</strong> number of flips required to make <code>s</code> equal to the reverse of its original form.</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<div class="example-block">
15+
<p><strong>Input:</strong> <span class="example-io">n = 7</span></p>
16+
17+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
18+
19+
<p><strong>Explanation:</strong></p>
20+
21+
<p>The binary representation of 7 is <code>&quot;111&quot;</code>. Its reverse is also <code>&quot;111&quot;</code>, which is the same. Hence, no flips are needed.</p>
22+
</div>
23+
24+
<p><strong class="example">Example 2:</strong></p>
25+
26+
<div class="example-block">
27+
<p><strong>Input:</strong> <span class="example-io">n = 10</span></p>
28+
29+
<p><strong>Output:</strong> <span class="example-io">4</span></p>
30+
31+
<p><strong>Explanation:</strong></p>
32+
33+
<p>The binary representation of 10 is <code>&quot;1010&quot;</code>. Its reverse is <code>&quot;0101&quot;</code>. All four bits must be flipped to make them equal. Thus, the minimum number of flips required is 4.</p>
34+
</div>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
41+
</ul>

0 commit comments

Comments
 (0)