java.lang.Object
g2001_2100.s2060_check_if_an_original_string_exists_given_two_encoded_strings.Solution

public class Solution extends Object
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>&quot;abcdefghijklmnop&quot;</code> might be:</p> <ul> <li>Split it as a sequence: <code>[&quot;ab&quot;, &quot;cdefghijklmn&quot;, &quot;o&quot;, &quot;p&quot;]</code>.</li> <li>Choose the second and third elements to be replaced by their lengths, respectively. The sequence becomes <code>[&quot;ab&quot;, &quot;12&quot;, &quot;1&quot;, &quot;p&quot;]</code>.</li> <li>Concatenate the elements of the sequence to get the encoded string: <code>&quot;ab121p&quot;</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 = &ldquo;internationalization&rdquo;, s2 = &ldquo;i18n&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> It is possible that &ldquo;internationalization&rdquo; was the original string.</p> <ul> <li> <p>&ldquo;internationalization&rdquo;</p> <p>-> Split: [&ldquo;internationalization&rdquo;]</p> <p>-> Do not replace any element</p> <p>-> Concatenate: &ldquo;internationalization&rdquo;, which is s1.</p> </li> <li> <p>&ldquo;internationalization&rdquo;</p> <p>-> Split: [&ldquo;i&rdquo;, &ldquo;nternationalizatio&rdquo;, &ldquo;n&rdquo;]</p> <p>-> Replace: [&ldquo;i&rdquo;, &ldquo;18&rdquo;, &ldquo;n&rdquo;]</p> <p>-> Concatenate: &ldquo;i18n&rdquo;, which is s2</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;l123e&rdquo;, s2 = &ldquo;44&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> It is possible that &ldquo;leetcode&rdquo; was the original string.</p> <ul> <li> <p>&ldquo;leetcode&rdquo;</p> <p>-> Split: [&ldquo;l&rdquo;, &ldquo;e&rdquo;, &ldquo;et&rdquo;, &ldquo;cod&rdquo;, &ldquo;e&rdquo;]</p> <p>-> Replace: [&ldquo;l&rdquo;, &ldquo;1&rdquo;, &ldquo;2&rdquo;, &ldquo;3&rdquo;, &ldquo;e&rdquo;]</p> <p>-> Concatenate: &ldquo;l123e&rdquo;, which is s1.</p> </li> <li> <p>&ldquo;leetcode&rdquo;</p> <p>-> Split: [&ldquo;leet&rdquo;, &ldquo;code&rdquo;]</p> <p>-> Replace: [&ldquo;4&rdquo;, &ldquo;4&rdquo;]</p> <p>-> Concatenate: &ldquo;44&rdquo;, which is s2.</p> </li> </ul> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;a5b&rdquo;, s2 = &ldquo;c5b&rdquo;</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 &lsquo;a&rsquo;.</p> </li> <li> <p>The original string encoded as s2 must start with the letter &lsquo;c&rsquo;.</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 Details

    • Solution

      public Solution()
  • Method Details

    • possiblyEquals

      public boolean possiblyEquals(String s1, String s2)