java.lang.Object
g2401_2500.s2405_optimal_partition_of_string.Solution

public class Solution extends Object
2405 - Optimal Partition of String.<p>Medium</p> <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p> <p>Return <em>the <strong>minimum</strong> number of substrings in such a partition.</em></p> <p>Note that each character should belong to exactly one substring in a partition.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abacaba&rdquo;</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong></p> <p>Two possible partitions are (&ldquo;a&rdquo;,&ldquo;ba&rdquo;,&ldquo;cab&rdquo;,&ldquo;a&rdquo;) and (&ldquo;ab&rdquo;,&ldquo;a&rdquo;,&ldquo;ca&rdquo;,&ldquo;ba&rdquo;).</p> <p>It can be shown that 4 is the minimum number of substrings needed.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;ssssss&rdquo;</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong></p> <p>The only valid partition is (&ldquo;s&rdquo;,&ldquo;s&rdquo;,&ldquo;s&rdquo;,&ldquo;s&rdquo;,&ldquo;s&rdquo;,&ldquo;s&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 English lowercase letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • partitionString

      public int partitionString(String s)