You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2><ahref="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 → 1</code> or <code>1 → 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>
<p>The binary representation of 7 is <code>"111"</code>. Its reverse is also <code>"111"</code>, which is the same. Hence, no flips are needed.</p>
<p>The binary representation of 10 is <code>"1010"</code>. Its reverse is <code>"0101"</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> </p>
37
+
<p><strong>Constraints:</strong></p>
38
+
39
+
<ul>
40
+
<li><code>1 <= n <= 10<sup>9</sup></code></li>
0 commit comments