java.lang.Object
g1401_1500.s1422_maximum_score_after_splitting_a_string.Solution

public class Solution extends Object
1422 - Maximum Score After Splitting a String.<p>Easy</p> <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> <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> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;011101&rdquo;</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> All possible ways of splitting s into two non-empty substrings are:</p> <p>left = &ldquo;0&rdquo; and right = &ldquo;11101&rdquo;, score = 1 + 4 = 5</p> <p>left = &ldquo;01&rdquo; and right = &ldquo;1101&rdquo;, score = 1 + 3 = 4</p> <p>left = &ldquo;011&rdquo; and right = &ldquo;101&rdquo;, score = 1 + 2 = 3</p> <p>left = &ldquo;0111&rdquo; and right = &ldquo;01&rdquo;, score = 1 + 1 = 2</p> <p>left = &ldquo;01110&rdquo; and right = &ldquo;1&rdquo;, score = 2 + 1 = 3</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;00111&rdquo;</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> When left = &ldquo;00&rdquo; and right = &ldquo;111&rdquo;, we get the maximum score = 2 + 3 = 5</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;1111&rdquo;</p> <p><strong>Output:</strong> 3</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= s.length <= 500</code></li> <li>The string <code>s</code> consists of characters <code>'0'</code> and <code>'1'</code> only.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxScore

      public int maxScore(String s)