2023-12-09 18:42:21 +08:00
|
|
|
|
<p>给你一个字符串 <code>s</code> 。我们要把这个字符串划分为尽可能多的片段,同一字母最多出现在一个片段中。</p>
|
2022-03-27 20:46:41 +08:00
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>注意,划分结果需要满足:将所有划分结果按顺序连接,得到的字符串仍然是 <code>s</code> 。</p>
|
2022-03-27 20:46:41 +08:00
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>返回一个表示每个字符串片段的长度的列表。</p>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
<strong class="example">示例 1:</strong>
|
2022-03-27 20:46:41 +08:00
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入:</strong>s = "ababcbacadefegdehijhklij"
|
2022-03-27 20:46:41 +08:00
|
|
|
|
<strong>输出:</strong>[9,7,8]
|
|
|
|
|
<strong>解释:</strong>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
划分结果为 "ababcbaca"、"defegde"、"hijhklij" 。
|
2022-03-27 20:46:41 +08:00
|
|
|
|
每个字母最多出现在一个片段中。
|
2023-12-09 18:42:21 +08:00
|
|
|
|
像 "ababcbacadefegde", "hijhklij" 这样的划分是错误的,因为划分的片段数较少。 </pre>
|
|
|
|
|
|
|
|
|
|
<p><strong class="example">示例 2:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
<strong>输入:</strong>s = "eccbbbbdec"
|
|
|
|
|
<strong>输出:</strong>[10]
|
2022-03-27 20:46:41 +08:00
|
|
|
|
</pre>
|
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p> </p>
|
2022-03-27 20:46:41 +08:00
|
|
|
|
|
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<li><code>1 <= s.length <= 500</code></li>
|
|
|
|
|
<li><code>s</code> 仅由小写英文字母组成</li>
|
2022-03-27 20:46:41 +08:00
|
|
|
|
</ul>
|