Class Solution
java.lang.Object
g2001_2100.s2060_check_if_an_original_string_exists_given_two_encoded_strings.Solution
2060 - Check if an Original String Exists Given Two Encoded Strings.<p>Hard</p>
<p>An original string, consisting of lowercase English letters, can be encoded by the following steps:</p>
<ul>
<li>Arbitrarily <strong>split</strong> it into a <strong>sequence</strong> of some number of <strong>non-empty</strong> substrings.</li>
<li>Arbitrarily choose some elements (possibly none) of the sequence, and <strong>replace</strong> each with <strong>its length</strong> (as a numeric string).</li>
<li><strong>Concatenate</strong> the sequence as the encoded string.</li>
</ul>
<p>For example, <strong>one way</strong> to encode an original string <code>"abcdefghijklmnop"</code> might be:</p>
<ul>
<li>Split it as a sequence: <code>["ab", "cdefghijklmn", "o", "p"]</code>.</li>
<li>Choose the second and third elements to be replaced by their lengths, respectively. The sequence becomes <code>["ab", "12", "1", "p"]</code>.</li>
<li>Concatenate the elements of the sequence to get the encoded string: <code>"ab121p"</code>.</li>
</ul>
<p>Given two encoded strings <code>s1</code> and <code>s2</code>, consisting of lowercase English letters and digits <code>1-9</code> (inclusive), return <code>true</code> <em>if there exists an original string that could be encoded as <strong>both</strong></em> <code>s1</code> <em>and</em> <code>s2</code><em>. Otherwise, return</em> <code>false</code>.</p>
<p><strong>Note</strong>: The test cases are generated such that the number of consecutive digits in <code>s1</code> and <code>s2</code> does not exceed <code>3</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s1 = “internationalization”, s2 = “i18n”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> It is possible that “internationalization” was the original string.</p>
<ul>
<li>
<p>“internationalization”</p>
<p>-> Split: [“internationalization”]</p>
<p>-> Do not replace any element</p>
<p>-> Concatenate: “internationalization”, which is s1.</p>
</li>
<li>
<p>“internationalization”</p>
<p>-> Split: [“i”, “nternationalizatio”, “n”]</p>
<p>-> Replace: [“i”, “18”, “n”]</p>
<p>-> Concatenate: “i18n”, which is s2</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s1 = “l123e”, s2 = “44”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> It is possible that “leetcode” was the original string.</p>
<ul>
<li>
<p>“leetcode”</p>
<p>-> Split: [“l”, “e”, “et”, “cod”, “e”]</p>
<p>-> Replace: [“l”, “1”, “2”, “3”, “e”]</p>
<p>-> Concatenate: “l123e”, which is s1.</p>
</li>
<li>
<p>“leetcode”</p>
<p>-> Split: [“leet”, “code”]</p>
<p>-> Replace: [“4”, “4”]</p>
<p>-> Concatenate: “44”, which is s2.</p>
</li>
</ul>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s1 = “a5b”, s2 = “c5b”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> It is impossible.</p>
<ul>
<li>
<p>The original string encoded as s1 must start with the letter ‘a’.</p>
</li>
<li>
<p>The original string encoded as s2 must start with the letter ‘c’.</p>
</li>
</ul>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s1.length, s2.length <= 40</code></li>
<li><code>s1</code> and <code>s2</code> consist of digits <code>1-9</code> (inclusive), and lowercase English letters only.</li>
<li>The number of consecutive digits in <code>s1</code> and <code>s2</code> does not exceed <code>3</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
possiblyEquals
-