mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
38 lines
1.8 KiB
HTML
38 lines
1.8 KiB
HTML
|
<p>Given two strings: <code>s1</code> and <code>s2</code> with the same size, check if some permutation of string <code>s1</code> can break some permutation of string <code>s2</code> or vice-versa. In other words <code>s2</code> can break <code>s1</code> or vice-versa.</p>
|
||
|
|
||
|
<p>A string <code>x</code> can break string <code>y</code> (both of size <code>n</code>) if <code>x[i] >= y[i]</code> (in alphabetical order) for all <code>i</code> between <code>0</code> and <code>n-1</code>.</p>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong>Example 1:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> s1 = "abc", s2 = "xya"
|
||
|
<strong>Output:</strong> true
|
||
|
<strong>Explanation:</strong> "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".
|
||
|
</pre>
|
||
|
|
||
|
<p><strong>Example 2:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> s1 = "abe", s2 = "acd"
|
||
|
<strong>Output:</strong> false
|
||
|
<strong>Explanation:</strong> All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
|
||
|
</pre>
|
||
|
|
||
|
<p><strong>Example 3:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> s1 = "leetcodee", s2 = "interview"
|
||
|
<strong>Output:</strong> true
|
||
|
</pre>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong>Constraints:</strong></p>
|
||
|
|
||
|
<ul>
|
||
|
<li><code>s1.length == n</code></li>
|
||
|
<li><code>s2.length == n</code></li>
|
||
|
<li><code>1 <= n <= 10^5</code></li>
|
||
|
<li>All strings consist of lowercase English letters.</li>
|
||
|
</ul>
|