# 交错字符串

<p>给定三个字符串 <code>s1</code>、<code>s2</code>、<code>s3</code>，请你帮忙验证 <code>s3</code> 是否是由 <code>s1</code> 和 <code>s2</code><em> </em><strong>交错 </strong>组成的。</p><p>两个字符串 <code>s</code> 和 <code>t</code> <strong>交错</strong> 的定义与过程如下，其中每个字符串都会被分割成若干 <strong>非空</strong> 子字符串：</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><strong>交错</strong> 是 <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> 或者 <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>提示：</strong><code>a + b</code> 意味着字符串 <code>a</code> 和 <code>b</code> 连接。</p><p> </p><p><strong>示例 1：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/d01d6f6906b7777c9823a97e68b77d06.jpeg" style="width: 561px; height: 203px;" /><pre><strong>输入：</strong>s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"<strong><br />输出：</strong>true</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"<strong><br />输出：</strong>false</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>s1 = "", s2 = "", s3 = ""<strong><br />输出：</strong>true</pre><p> </p><p><strong>提示：</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>、和 <code>s3</code> 都由小写英文字母组成</li></ul>

## template

```python
class Solution(object):
	def isInterleave(self, s1, s2, s3):
		"""
		:type s1: str
		:type s2: str
		:type s3: str
		:rtype: bool
		"""
		if len(s1) + len(s2) != len(s3):
			return False
		queue = [(0, 0), (-1, -1)]
		visited = set()
		isSuccess = False
		index = 0
		while len(queue) != 1 or queue[0][0] != -1:
			p = queue.pop(0)
			if p[0] == len(s1) and p[1] == len(s2):
				return True
			if p[0] == -1:
				queue.append(p)
				index += 1
				continue
			if p in visited:
				continue
			visited.add(p)
			if p[0] < len(s1):
				if s1[p[0]] == s3[index]:
					queue.append((p[0] + 1, p[1]))
			if p[1] < len(s2):
				if s2[p[1]] == s3[index]:
					queue.append((p[0], p[1] + 1))
		return False
# %%
s = Solution()
print(s.isInterleave(s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```