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)/检查一个字符串是否可以打破另一个字符串 [check-if-a-string-can-break-another-string].html
2022-03-29 12:43:11 +08:00

37 lines
2.0 KiB
HTML
Raw Permalink 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>s1</code>&nbsp;&nbsp;<code>s2</code>&nbsp;,它们长度相等,请你检查是否存在一个&nbsp;<code>s1</code>&nbsp; 的排列可以打破 <code>s2</code>&nbsp;的一个排列,或者是否存在一个&nbsp;<code>s2</code>&nbsp;的排列可以打破 <code>s1</code> 的一个排列。</p>
<p>字符串&nbsp;<code>x</code>&nbsp;可以打破字符串&nbsp;<code>y</code>&nbsp;(两者长度都为&nbsp;<code>n</code>&nbsp;)需满足对于所有&nbsp;<code>i</code>(在&nbsp;<code>0</code>&nbsp;&nbsp;<code>n - 1</code>&nbsp;之间)都有&nbsp;<code>x[i] &gt;= y[i]</code>(字典序意义下的顺序)。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s1 = &quot;abc&quot;, s2 = &quot;xya&quot;
<strong>输出:</strong>true
<strong>解释:</strong>&quot;ayx&quot; 是 s2=&quot;xya&quot; 的一个排列,&quot;abc&quot; 是字符串 s1=&quot;abc&quot; 的一个排列,且 &quot;ayx&quot; 可以打破 &quot;abc&quot;
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s1 = &quot;abe&quot;, s2 = &quot;acd&quot;
<strong>输出:</strong>false
<strong>解释:</strong>s1=&quot;abe&quot; 的所有排列包括:&quot;abe&quot;&quot;aeb&quot;&quot;bae&quot;&quot;bea&quot;&quot;eab&quot;&quot;eba&quot; s2=&quot;acd&quot; 的所有排列包括:&quot;acd&quot;&quot;adc&quot;&quot;cad&quot;&quot;cda&quot;&quot;dac&quot;&quot;dca&quot;。然而没有任何 s1 的排列可以打破 s2 的排列。也没有 s2 的排列能打破 s1 的排列。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>s1 = &quot;leetcodee&quot;, s2 = &quot;interview&quot;
<strong>输出:</strong>true
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>s1.length == n</code></li>
<li><code>s2.length == n</code></li>
<li><code>1 &lt;= n &lt;= 10^5</code></li>
<li>所有字符串都只包含小写英文字母。</li>
</ul>