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)/将字符串分割成值不超过 K 的子字符串 [partition-string-into-substrings-with-values-at-most-k].html
2023-01-04 16:53:10 +08:00

47 lines
1.9 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>给你一个字符串&nbsp;<code>s</code>&nbsp;,它每一位都是&nbsp;<code>1</code>&nbsp;&nbsp;<code>9</code>&nbsp;之间的数字组成,同时给你一个整数&nbsp;<code>k</code>&nbsp;</p>
<p>如果一个字符串 <code>s</code>&nbsp;的分割满足以下条件,我们称它是一个 <strong></strong>&nbsp;分割:</p>
<ul>
<li><code>s</code>&nbsp;中每个数位 <strong>恰好</strong>&nbsp;属于一个子字符串。</li>
<li>每个子字符串的值都小于等于&nbsp;<code>k</code>&nbsp;</li>
</ul>
<p>请你返回 <code>s</code>&nbsp;所有的 <strong></strong>&nbsp;分割中,子字符串的&nbsp;<strong>最少</strong>&nbsp;数目。如果不存在 <code>s</code>&nbsp;<strong>&nbsp;</strong>&nbsp;分割,返回&nbsp;<code>-1</code>&nbsp;</p>
<p><b>注意:</b></p>
<ul>
<li>一个字符串的 <strong></strong>&nbsp;是这个字符串对应的整数。比方说,<code>"123"</code>&nbsp;的值为&nbsp;<code>123</code>&nbsp;<code>"1"</code>&nbsp;的值是&nbsp;<code>1</code>&nbsp;</li>
<li><strong>子字符串</strong>&nbsp;是字符串中一段连续的字符序列。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>s = "165462", k = 60
<b>输出:</b>4
<b>解释:</b>我们将字符串分割成子字符串 "16" "54" "6" 和 "2" 。每个子字符串的值都小于等于 k = 60 。
不存在小于 4 个子字符串的好分割。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>s = "238182", k = 5
<b>输出:</b>-1
<strong>解释:</strong>这个字符串不存在好分割。
</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[i]</code>&nbsp;&nbsp;<code>'1'</code>&nbsp;&nbsp;<code>'9'</code>&nbsp;之间的数字。</li>
<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>