1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/子字符串的最优划分 [optimal-partition-of-string].html

36 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个字符串 <code>s</code> ,请你将该字符串划分成一个或多个 <strong>子字符串</strong> ,并满足每个子字符串中的字符都是 <strong>唯一</strong> 的。也就是说,在单个子字符串中,字母的出现次数都不超过 <strong>一次</strong></p>
<p>满足题目要求的情况下,返回 <strong>最少</strong> 需要划分多少个子字符串<em></em></p>
<p>注意,划分后,原字符串中的每个字符都应该恰好属于一个子字符串。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "abacaba"
<strong>输出:</strong>4
<strong>解释:</strong>
两种可行的划分方法分别是 ("a","ba","cab","a") 和 ("ab","a","ca","ba") 。
可以证明最少需要划分 4 个子字符串。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "ssssss"
<strong>输出:</strong>6
<strong>解释:
</strong>只存在一种可行的划分方法 ("s","s","s","s","s","s") 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</code> 仅由小写英文字母组成</li>
</ul>