{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "7017d7f1a56842878210bfc80b093faa",
  "keywords": "字符串,动态规划",
  "title": "交错字符串",
  "desc": [
    {
      "content": "\n<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>\t<li><code>s = s<sub>1</sub> + s<sub>2</sub> + ... + s<sub>n</sub></code></li>\t<li><code>t = t<sub>1</sub> + t<sub>2</sub> + ... + t<sub>m</sub></code></li>\t<li><code>|n - m| <= 1</code></li>\t<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://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0097.Interleaving%20String/images/interleave.jpg\" 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>\t<li><code>0 <= s1.length, s2.length <= 100</code></li>\t<li><code>0 <= s3.length <= 200</code></li>\t<li><code>s1</code>、<code>s2</code>、和 <code>s3</code> 都由小写英文字母组成</li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "class Solution {\n\tpublic boolean isInterleave(String s1, String s2, String s3) {\n\t\tif ((s1.length() + s2.length()) != s3.length())\n\t\t\treturn false;\n\t\tboolean[][] dp = new boolean[s2.length() + 1][s1.length() + 1];\n\t\tdp[0][0] = true;\n\t\tfor (int i = 1; i <= s1.length(); i++) {\n\t\t\tdp[0][i] = dp[0][i - 1] && s1.charAt(i - 1) == s3.charAt(i - 1) ? true : false;\n\t\t}\n\t\tfor (int i = 1; i <= s2.length(); i++) {\n\t\t\tdp[i][0] = dp[i - 1][0] && s2.charAt(i - 1) == s3.charAt(i - 1) ? true : false;\n\t\t}\n\t\tfor (int i = 1; i < dp.length; i++) {\n\t\t\tfor (int j = 1; j < dp[0].length; j++) {\n\t\t\t\tdp[i][j] = (dp[i][j - 1] && s1.charAt(j - 1) == s3.charAt(i + j - 1))\n\t\t\t\t\t\t|| (dp[i - 1][j] && s2.charAt(i - 1) == s3.charAt(i + j - 1));\n\t\t\t}\n\t\t}\n\t\treturn dp[s2.length()][s1.length()];\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-a4f351932be94d9388ffb510d2ff8dc4",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600471101"
}