Skip to content

Commit deb3286

Browse files
committed
Create README - LeetHub
1 parent 4878513 commit deb3286

File tree

1 file changed

+48
-0
lines changed
  • 2914-minimum-number-of-changes-to-make-binary-string-beautiful

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<h2><a href="https://leetcode.com/problems/minimum-number-of-changes-to-make-binary-string-beautiful/">2914. Minimum Number of Changes to Make Binary String Beautiful</a></h2><h3>Medium</h3><hr><div><p>You are given a <strong>0-indexed</strong> binary string <code>s</code> having an even length.</p>
2+
3+
<p>A string is <strong>beautiful</strong> if it's possible to partition it into one or more substrings such that:</p>
4+
5+
<ul>
6+
<li>Each substring has an <strong>even length</strong>.</li>
7+
<li>Each substring contains <strong>only</strong> <code>1</code>'s or <strong>only</strong> <code>0</code>'s.</li>
8+
</ul>
9+
10+
<p>You can change any character in <code>s</code> to <code>0</code> or <code>1</code>.</p>
11+
12+
<p>Return <em>the <strong>minimum</strong> number of changes required to make the string </em><code>s</code> <em>beautiful</em>.</p>
13+
14+
<p>&nbsp;</p>
15+
<p><strong class="example">Example 1:</strong></p>
16+
17+
<pre><strong>Input:</strong> s = "1001"
18+
<strong>Output:</strong> 2
19+
<strong>Explanation:</strong> We change s[1] to 1 and s[3] to 0 to get string "1100".
20+
It can be seen that the string "1100" is beautiful because we can partition it into "11|00".
21+
It can be proven that 2 is the minimum number of changes needed to make the string beautiful.
22+
</pre>
23+
24+
<p><strong class="example">Example 2:</strong></p>
25+
26+
<pre><strong>Input:</strong> s = "10"
27+
<strong>Output:</strong> 1
28+
<strong>Explanation:</strong> We change s[1] to 1 to get string "11".
29+
It can be seen that the string "11" is beautiful because we can partition it into "11".
30+
It can be proven that 1 is the minimum number of changes needed to make the string beautiful.
31+
</pre>
32+
33+
<p><strong class="example">Example 3:</strong></p>
34+
35+
<pre><strong>Input:</strong> s = "0000"
36+
<strong>Output:</strong> 0
37+
<strong>Explanation:</strong> We don't need to make any changes as the string "0000" is beautiful already.
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
<p><strong>Constraints:</strong></p>
42+
43+
<ul>
44+
<li><code>2 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
45+
<li><code>s</code> has an even length.</li>
46+
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
47+
</ul>
48+
</div>

0 commit comments

Comments
 (0)