java.lang.Object
g1501_1600.s1525_number_of_good_ways_to_split_a_string.Solution

public class Solution extends Object
1525 - Number of Good Ways to Split a String.<p>Medium</p> <p>You are given a string <code>s</code>.</p> <p>A split is called <strong>good</strong> if you can split <code>s</code> into two non-empty strings <code>s<sub>left</sub></code> and <code>s<sub>right</sub></code> where their concatenation is equal to <code>s</code> (i.e., <code>s<sub>left</sub> + s<sub>right</sub> = s</code>) and the number of distinct letters in <code>s<sub>left</sub></code> and <code>s<sub>right</sub></code> is the same.</p> <p>Return <em>the number of <strong>good splits</strong> you can make in <code>s</code></em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;aacaba&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> There are 5 ways to split <code>&quot;aacaba&quot;</code> and 2 of them are good.</p> <p>(&ldquo;a&rdquo;, &ldquo;acaba&rdquo;) Left string and right string contains 1 and 3 different letters respectively.</p> <p>(&ldquo;aa&rdquo;, &ldquo;caba&rdquo;) Left string and right string contains 1 and 3 different letters respectively.</p> <p>(&ldquo;aac&rdquo;, &ldquo;aba&rdquo;) Left string and right string contains 2 and 2 different letters respectively (good split).</p> <p>(&ldquo;aaca&rdquo;, &ldquo;ba&rdquo;) Left string and right string contains 2 and 2 different letters respectively (good split).</p> <p>(&ldquo;aacab&rdquo;, &ldquo;a&rdquo;) Left string and right string contains 3 and 1 different letters respectively.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcd&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> Split the string as follows (&ldquo;ab&rdquo;, &ldquo;cd&rdquo;).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s</code> consists of only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numSplits

      public int numSplits(String s)