Class Solution
java.lang.Object
g0001_0100.s0097_interleaving_string.Solution
97 - Interleaving String.<p>Medium</p>
<p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where they are divided into <strong>non-empty</strong> substrings such that:</p>
<ul>
<li><code>s = s<sub>1</sub> + s<sub>2</sub> + … + s<sub>n</sub></code></li>
<li><code>t = t<sub>1</sub> + t<sub>2</sub> + … + t<sub>m</sub></code></li>
<li><code>|n - m| <= 1</code></li>
<li>The <strong>interleaving</strong> is <code>s<sub>1</sub> + t<sub>1</sub> + s<sub>2</sub> + t<sub>2</sub> + s<sub>3</sub> + t<sub>3</sub> + …</code> or <code>t<sub>1</sub> + s<sub>1</sub> + t<sub>2</sub> + s<sub>2</sub> + t<sub>3</sub> + s<sub>3</sub> + …</code></li>
</ul>
<p><strong>Note:</strong> <code>a + b</code> is the concatenation of strings <code>a</code> and <code>b</code>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/02/interleave.jpg" alt="" /></p>
<p><strong>Input:</strong> s1 = “aabcc”, s2 = “dbbca”, s3 = “aadbbcbcac”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s1 = “aabcc”, s2 = “dbbca”, s3 = “aadbbbaccc”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s1 = "", s2 = "", s3 = ""</p>
<p><strong>Output:</strong> true</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 <= s1.length, s2.length <= 100</code></li>
<li><code>0 <= s3.length <= 200</code></li>
<li><code>s1</code>, <code>s2</code>, and <code>s3</code> consist of lowercase English letters.</li>
</ul>
<p><strong>Follow up:</strong> Could you solve it using only <code>O(s2.length)</code> additional memory space?</p>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
isInterleave
(String s1, String s2, String s3) boolean
isInterleave
(String s1, String s2, String s3, int i1, int i2, int i3, Boolean[][] cache)
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isInterleave
-
isInterleave
-