mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			51 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> having an even length.</p>
 | 
						|
 | 
						|
<p>A string is <strong>beautiful</strong> if it's possible to partition it into one or more substrings such that:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>Each substring has an <strong>even length</strong>.</li>
 | 
						|
	<li>Each substring contains <strong>only</strong> <code>1</code>'s or <strong>only</strong> <code>0</code>'s.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p>You can change any character in <code>s</code> to <code>0</code> or <code>1</code>.</p>
 | 
						|
 | 
						|
<p>Return <em>the <strong>minimum</strong> number of changes required to make the string </em><code>s</code> <em>beautiful</em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "1001"
 | 
						|
<strong>Output:</strong> 2
 | 
						|
<strong>Explanation:</strong> We change s[1] to 1 and s[3] to 0 to get string "1100".
 | 
						|
It can be seen that the string "1100" is beautiful because we can partition it into "11|00".
 | 
						|
It can be proven that 2 is the minimum number of changes needed to make the string beautiful.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "10"
 | 
						|
<strong>Output:</strong> 1
 | 
						|
<strong>Explanation:</strong> We change s[1] to 1 to get string "11".
 | 
						|
It can be seen that the string "11" is beautiful because we can partition it into "11".
 | 
						|
It can be proven that 1 is the minimum number of changes needed to make the string beautiful.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "0000"
 | 
						|
<strong>Output:</strong> 0
 | 
						|
<strong>Explanation:</strong> We don't need to make any changes as the string "0000" is beautiful already.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>2 <= s.length <= 10<sup>5</sup></code></li>
 | 
						|
	<li><code>s</code> has an even length.</li>
 | 
						|
	<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
 | 
						|
</ul>
 |