Skip to content

Commit 8195cc6

Browse files
committed
Create README - LeetHub
1 parent a5c7507 commit 8195cc6

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

0097-interleaving-string/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<h2><a href="https://leetcode.com/problems/interleaving-string">97. Interleaving String</a></h2><h3>Medium</h3><hr><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>
2+
3+
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and <code>t</code> are divided into <code>n</code> and <code>m</code> <span data-keyword="substring-nonempty">substrings</span> respectively, such that:</p>
4+
5+
<ul>
6+
<li><code>s = s<sub>1</sub> + s<sub>2</sub> + ... + s<sub>n</sub></code></li>
7+
<li><code>t = t<sub>1</sub> + t<sub>2</sub> + ... + t<sub>m</sub></code></li>
8+
<li><code>|n - m| &lt;= 1</code></li>
9+
<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>
10+
</ul>
11+
12+
<p><strong>Note:</strong> <code>a + b</code> is the concatenation of strings <code>a</code> and <code>b</code>.</p>
13+
14+
<p>&nbsp;</p>
15+
<p><strong class="example">Example 1:</strong></p>
16+
<img alt="" src="https://assets.leetcode.com/uploads/2020/09/02/interleave.jpg" style="width: 561px; height: 203px;" />
17+
<pre>
18+
<strong>Input:</strong> s1 = &quot;aabcc&quot;, s2 = &quot;dbbca&quot;, s3 = &quot;aadbbcbcac&quot;
19+
<strong>Output:</strong> true
20+
<strong>Explanation:</strong> One way to obtain s3 is:
21+
Split s1 into s1 = &quot;aa&quot; + &quot;bc&quot; + &quot;c&quot;, and s2 into s2 = &quot;dbbc&quot; + &quot;a&quot;.
22+
Interleaving the two splits, we get &quot;aa&quot; + &quot;dbbc&quot; + &quot;bc&quot; + &quot;a&quot; + &quot;c&quot; = &quot;aadbbcbcac&quot;.
23+
Since s3 can be obtained by interleaving s1 and s2, we return true.
24+
</pre>
25+
26+
<p><strong class="example">Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> s1 = &quot;aabcc&quot;, s2 = &quot;dbbca&quot;, s3 = &quot;aadbbbaccc&quot;
30+
<strong>Output:</strong> false
31+
<strong>Explanation:</strong> Notice how it is impossible to interleave s2 with any other string to obtain s3.
32+
</pre>
33+
34+
<p><strong class="example">Example 3:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> s1 = &quot;&quot;, s2 = &quot;&quot;, s3 = &quot;&quot;
38+
<strong>Output:</strong> true
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Constraints:</strong></p>
43+
44+
<ul>
45+
<li><code>0 &lt;= s1.length, s2.length &lt;= 100</code></li>
46+
<li><code>0 &lt;= s3.length &lt;= 200</code></li>
47+
<li><code>s1</code>, <code>s2</code>, and <code>s3</code> consist of lowercase English letters.</li>
48+
</ul>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Follow up:</strong> Could you solve it using only <code>O(s2.length)</code> additional memory space?</p>

0 commit comments

Comments
 (0)