1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/将字符串拆分为递减的连续值 [splitting-a-string-into-descending-consecutive-values].html
2022-03-29 12:43:11 +08:00

57 lines
2.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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></p>
<p>请你判断能否将 <code>s</code> 拆分成两个或者多个 <strong>非空子字符串</strong> ,使子字符串的 <strong>数值</strong><strong>降序</strong> 排列,且每两个 <strong>相邻子字符串</strong> 的数值之 <strong></strong>等于 <code>1</code></p>
<ul>
<li>例如,字符串 <code>s = "0090089"</code> 可以拆分成 <code>["0090", "089"]</code> ,数值为 <code>[90,89]</code> 。这些数值满足按降序排列,且相邻值相差 <code>1</code> ,这种拆分方法可行。</li>
<li>另一个例子中,字符串 <code>s = "001"</code> 可以拆分成 <code>["0", "01"]</code><code>["00", "1"]</code><code>["0", "0", "1"]</code> 。然而,所有这些拆分方法都不可行,因为对应数值分别是 <code>[0,1]</code><code>[0,1]</code><code>[0,0,1]</code> ,都不满足按降序排列的要求。</li>
</ul>
<p>如果可以按要求拆分 <code>s</code> ,返回 <code>true</code> ;否则,返回 <code>false</code><em> </em></p>
<p><strong>子字符串</strong> 是字符串中的一个连续字符序列。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "1234"
<strong>输出:</strong>false
<strong>解释:</strong>不存在拆分 s 的可行方法。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "050043"
<strong>输出:</strong>true
<strong>解释:</strong>s 可以拆分为 ["05", "004", "3"] ,对应数值为 [5,4,3] 。
满足按降序排列,且相邻值相差 <code>1</code>
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "9080701"
<strong>输出:</strong>false
<strong>解释:</strong>不存在拆分 s 的可行方法。
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>s = "10009998"
<strong>输出:</strong>true
<strong>解释:</strong>s 可以拆分为 ["100", "099", "98"] ,对应数值为 [100,99,98] 。
满足按降序排列,且相邻值相差 <code>1</code></pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= s.length <= 20</code></li>
<li><code>s</code> 仅由数字组成</li>
</ul>