mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个字符串 <code>word</code> ,你可以向其中任何位置插入 "a"、"b" 或 "c" 任意次,返回使 <code>word</code> <strong>有效</strong> 需要插入的最少字母数。</p>
 | 
						||
 | 
						||
<p>如果字符串可以由 "abc" 串联多次得到,则认为该字符串 <strong>有效</strong> 。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>word = "b"
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>在 "b" 之前插入 "a" ,在 "b" 之后插入 "c" 可以得到有效字符串 "<strong>a</strong>b<strong>c</strong>" 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>word = "aaa"
 | 
						||
<strong>输出:</strong>6
 | 
						||
<strong>解释:</strong>在每个 "a" 之后依次插入 "b" 和 "c" 可以得到有效字符串 "a<strong>bc</strong>a<strong>bc</strong>a<strong>bc</strong>" 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>word = "abc"
 | 
						||
<strong>输出:</strong>0
 | 
						||
<strong>解释:</strong>word 已经是有效字符串,不需要进行修改。 
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= word.length <= 50</code></li>
 | 
						||
	<li><code>word</code> 仅由字母 "a"、"b" 和 "c" 组成。</li>
 | 
						||
</ul>
 |