|
| 1 | +<p>Given a string <code>s</code> of zeros and ones, <em>return the maximum score after splitting the string into two <strong>non-empty</strong> substrings</em> (i.e. <strong>left</strong> substring and <strong>right</strong> substring).</p> |
| 2 | + |
| 3 | +<p>The score after splitting a string is the number of <strong>zeros</strong> in the <strong>left</strong> substring plus the number of <strong>ones</strong> in the <strong>right</strong> substring.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> s = "011101" |
| 10 | +<strong>Output:</strong> 5 |
| 11 | +<strong>Explanation:</strong> |
| 12 | +All possible ways of splitting s into two non-empty substrings are: |
| 13 | +left = "0" and right = "11101", score = 1 + 4 = 5 |
| 14 | +left = "01" and right = "1101", score = 1 + 3 = 4 |
| 15 | +left = "011" and right = "101", score = 1 + 2 = 3 |
| 16 | +left = "0111" and right = "01", score = 1 + 1 = 2 |
| 17 | +left = "01110" and right = "1", score = 2 + 1 = 3 |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> s = "00111" |
| 24 | +<strong>Output:</strong> 5 |
| 25 | +<strong>Explanation:</strong> When left = "00" and right = "111", we get the maximum score = 2 + 3 = 5 |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p><strong class="example">Example 3:</strong></p> |
| 29 | + |
| 30 | +<pre> |
| 31 | +<strong>Input:</strong> s = "1111" |
| 32 | +<strong>Output:</strong> 3 |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>2 <= s.length <= 500</code></li> |
| 40 | + <li>The string <code>s</code> consists of characters <code>'0'</code> and <code>'1'</code> only.</li> |
| 41 | +</ul> |
0 commit comments