1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/分割字符串的最大得分 [maximum-score-after-splitting-a-string].html
2022-03-29 12:43:11 +08:00

41 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个由若干 0 和 1 组成的字符串 <code>s</code> ,请你计算并返回将该字符串分割成两个 <strong>非空</strong> 子字符串(即&nbsp;<strong></strong> 子字符串和 <strong></strong> 子字符串)所能获得的最大得分。</p>
<p>「分割字符串的得分」为 <strong></strong> 子字符串中 <strong>0</strong> 的数量加上 <strong></strong> 子字符串中 <strong>1</strong> 的数量。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s = &quot;011101&quot;
<strong>输出:</strong>5
<strong>解释:</strong>
将字符串 s 划分为两个非空子字符串的可行方案有:
左子字符串 = &quot;0&quot; 且 右子字符串 = &quot;11101&quot;,得分 = 1 + 4 = 5
左子字符串 = &quot;01&quot; 且 右子字符串 = &quot;1101&quot;,得分 = 1 + 3 = 4
左子字符串 = &quot;011&quot; 且 右子字符串 = &quot;101&quot;,得分 = 1 + 2 = 3
左子字符串 = &quot;0111&quot; 且 右子字符串 = &quot;01&quot;,得分 = 1 + 1 = 2
左子字符串 = &quot;01110&quot; 且 右子字符串 = &quot;1&quot;,得分 = 2 + 1 = 3
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s = &quot;00111&quot;
<strong>输出:</strong>5
<strong>解释:</strong>当 左子字符串 = &quot;00&quot; 且 右子字符串 = &quot;111&quot; 时,我们得到最大得分 = 2 + 3 = 5
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>s = &quot;1111&quot;
<strong>输出:</strong>3
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= s.length &lt;= 500</code></li>
<li>字符串 <code>s</code> 仅由字符 <code>&#39;0&#39;</code><code>&#39;1&#39;</code> 组成。</li>
</ul>