mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
34 lines
1.3 KiB
HTML
34 lines
1.3 KiB
HTML
<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> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "abacaba"
|
|
<strong>Output:</strong> 4
|
|
<strong>Explanation:</strong>
|
|
Two possible partitions are ("a","ba","cab","a") and ("ab","a","ca","ba").
|
|
It can be shown that 4 is the minimum number of substrings needed.
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "ssssss"
|
|
<strong>Output:</strong> 6
|
|
<strong>Explanation:
|
|
</strong>The only valid partition is ("s","s","s","s","s","s").
|
|
</pre>
|
|
|
|
<p> </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>
|