mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			49 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given a string <code>s</code> consisting of lowercase English letters. Your task is to find the <strong>maximum</strong> difference between the frequency of <strong>two</strong> characters in the string such that:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>One of the characters has an <strong>even frequency</strong> in the string.</li>
 | 
						|
	<li>The other character has an <strong>odd frequency</strong> in the string.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p>Return the <strong>maximum</strong> difference, calculated as the frequency of the character with an <b>odd</b> frequency <strong>minus</strong> the frequency of the character with an <b>even</b> frequency.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">s = "aaaaabbc"</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> 3</p>
 | 
						|
 | 
						|
<p><strong>Explanation:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>The character <code>'a'</code> has an <strong>odd frequency</strong> of <code><font face="monospace">5</font></code><font face="monospace">,</font> and <code>'b'</code> has an <strong>even frequency</strong> of <code><font face="monospace">2</font></code>.</li>
 | 
						|
	<li>The maximum difference is <code>5 - 2 = 3</code>.</li>
 | 
						|
</ul>
 | 
						|
</div>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">s = "abcabcab"</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> 1</p>
 | 
						|
 | 
						|
<p><strong>Explanation:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>The character <code>'a'</code> has an <strong>odd frequency</strong> of <code><font face="monospace">3</font></code><font face="monospace">,</font> and <code>'c'</code> has an <strong>even frequency</strong> of <font face="monospace">2</font>.</li>
 | 
						|
	<li>The maximum difference is <code>3 - 2 = 1</code>.</li>
 | 
						|
</ul>
 | 
						|
</div>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>3 <= s.length <= 100</code></li>
 | 
						|
	<li><code>s</code> consists only of lowercase English letters.</li>
 | 
						|
	<li><code>s</code> contains at least one character with an odd frequency and one with an even frequency.</li>
 | 
						|
</ul>
 |