mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
172 lines
16 KiB
JSON
172 lines
16 KiB
JSON
|
{
|
||
|
"data": {
|
||
|
"question": {
|
||
|
"questionId": "97",
|
||
|
"questionFrontendId": "97",
|
||
|
"boundTopicId": null,
|
||
|
"title": "Interleaving String",
|
||
|
"titleSlug": "interleaving-string",
|
||
|
"content": "<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>\n\n<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>\n\n<ul>\n\t<li><code>s = s<sub>1</sub> + s<sub>2</sub> + ... + s<sub>n</sub></code></li>\n\t<li><code>t = t<sub>1</sub> + t<sub>2</sub> + ... + t<sub>m</sub></code></li>\n\t<li><code>|n - m| <= 1</code></li>\n\t<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>\n</ul>\n\n<p><strong>Note:</strong> <code>a + b</code> is the concatenation of strings <code>a</code> and <code>b</code>.</p>\n\n<p> </p>\n<p><strong>Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/09/02/interleave.jpg\" style=\"width: 561px; height: 203px;\" />\n<pre>\n<strong>Input:</strong> s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"\n<strong>Output:</strong> true\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"\n<strong>Output:</strong> false\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s1 = "", s2 = "", s3 = ""\n<strong>Output:</strong> true\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= s1.length, s2.length <= 100</code></li>\n\t<li><code>0 <= s3.length <= 200</code></li>\n\t<li><code>s1</code>, <code>s2</code>, and <code>s3</code> consist of lowercase English letters.</li>\n</ul>\n\n<p> </p>\n<p><strong>Follow up:</strong> Could you solve it using only <code>O(s2.length)</code> additional memory space?</p>\n",
|
||
|
"translatedTitle": null,
|
||
|
"translatedContent": null,
|
||
|
"isPaidOnly": false,
|
||
|
"difficulty": "Medium",
|
||
|
"likes": 3702,
|
||
|
"dislikes": 197,
|
||
|
"isLiked": null,
|
||
|
"similarQuestions": "[]",
|
||
|
"exampleTestcases": "\"aabcc\"\n\"dbbca\"\n\"aadbbcbcac\"\n\"aabcc\"\n\"dbbca\"\n\"aadbbbaccc\"\n\"\"\n\"\"\n\"\"",
|
||
|
"categoryTitle": "Algorithms",
|
||
|
"contributors": [],
|
||
|
"topicTags": [
|
||
|
{
|
||
|
"name": "String",
|
||
|
"slug": "string",
|
||
|
"translatedName": null,
|
||
|
"__typename": "TopicTagNode"
|
||
|
},
|
||
|
{
|
||
|
"name": "Dynamic Programming",
|
||
|
"slug": "dynamic-programming",
|
||
|
"translatedName": null,
|
||
|
"__typename": "TopicTagNode"
|
||
|
}
|
||
|
],
|
||
|
"companyTagStats": null,
|
||
|
"codeSnippets": [
|
||
|
{
|
||
|
"lang": "C++",
|
||
|
"langSlug": "cpp",
|
||
|
"code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n \n }\n};",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Java",
|
||
|
"langSlug": "java",
|
||
|
"code": "class Solution {\n public boolean isInterleave(String s1, String s2, String s3) {\n \n }\n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Python",
|
||
|
"langSlug": "python",
|
||
|
"code": "class Solution(object):\n def isInterleave(self, s1, s2, s3):\n \"\"\"\n :type s1: str\n :type s2: str\n :type s3: str\n :rtype: bool\n \"\"\"\n ",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Python3",
|
||
|
"langSlug": "python3",
|
||
|
"code": "class Solution:\n def isInterleave(self, s1: str, s2: str, s3: str) -> bool:\n ",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "C",
|
||
|
"langSlug": "c",
|
||
|
"code": "\n\nbool isInterleave(char * s1, char * s2, char * s3){\n\n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "C#",
|
||
|
"langSlug": "csharp",
|
||
|
"code": "public class Solution {\n public bool IsInterleave(string s1, string s2, string s3) {\n \n }\n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "JavaScript",
|
||
|
"langSlug": "javascript",
|
||
|
"code": "/**\n * @param {string} s1\n * @param {string} s2\n * @param {string} s3\n * @return {boolean}\n */\nvar isInterleave = function(s1, s2, s3) {\n \n};",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Ruby",
|
||
|
"langSlug": "ruby",
|
||
|
"code": "# @param {String} s1\n# @param {String} s2\n# @param {String} s3\n# @return {Boolean}\ndef is_interleave(s1, s2, s3)\n \nend",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Swift",
|
||
|
"langSlug": "swift",
|
||
|
"code": "class Solution {\n func isInterleave(_ s1: String, _ s2: String, _ s3: String) -> Bool {\n \n }\n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Go",
|
||
|
"langSlug": "golang",
|
||
|
"code": "func isInterleave(s1 string, s2 string, s3 string) bool {\n \n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Scala",
|
||
|
"langSlug": "scala",
|
||
|
"code": "object Solution {\n def isInterleave(s1: String, s2: String, s3: String): Boolean = {\n \n }\n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Kotlin",
|
||
|
"langSlug": "kotlin",
|
||
|
"code": "class Solution {\n fun isInterleave(s1: String, s2: String, s3: String): Boolean {\n \n }\n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Rust",
|
||
|
"langSlug": "rust",
|
||
|
"code": "impl Solution {\n pub fn is_interleave(s1: String, s2: String, s3: String) -> bool {\n \n }\n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "PHP",
|
||
|
"langSlug": "php",
|
||
|
"code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @param String $s3\n * @return Boolean\n */\n function isInterleave($s1, $s2, $s3) {\n \n }\n}",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "TypeScript",
|
||
|
"langSlug": "typescript",
|
||
|
"code": "function isInterleave(s1: string, s2: string, s3: string): boolean {\n\n};",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Racket",
|
||
|
"langSlug": "racket",
|
||
|
"code": "(define/contract (is-interleave s1 s2 s3)\n (-> string? string? string? boolean?)\n\n )",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Erlang",
|
||
|
"langSlug": "erlang",
|
||
|
"code": "-spec is_interleave(S1 :: unicode:unicode_binary(), S2 :: unicode:unicode_binary(), S3 :: unicode:unicode_binary()) -> boolean().\nis_interleave(S1, S2, S3) ->\n .",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "Elixir",
|
||
|
"langSlug": "elixir",
|
||
|
"code": "defmodule Solution do\n @spec is_interleave(s1 :: String.t, s2 :: String.t, s3 :: String.t) :: boolean\n def is_interleave(s1, s2, s3) do\n\n end\nend",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
}
|
||
|
],
|
||
|
"stats": "{\"totalAccepted\": \"256.3K\", \"totalSubmission\": \"740.4K\", \"totalAcceptedRaw\": 256296, \"totalSubmissionRaw\": 740412, \"acRate\": \"34.6%\"}",
|
||
|
"hints": [],
|
||
|
"solution": {
|
||
|
"id": "91",
|
||
|
"canSeeDetail": true,
|
||
|
"paidOnly": false,
|
||
|
"hasVideoSolution": false,
|
||
|
"paidOnlyVideo": true,
|
||
|
"__typename": "ArticleNode"
|
||
|
},
|
||
|
"status": null,
|
||
|
"sampleTestCase": "\"aabcc\"\n\"dbbca\"\n\"aadbbcbcac\"",
|
||
|
"metaData": "{ \r\n \"name\": \"isInterleave\",\r\n \"params\": [\r\n {\r\n \"name\": \"s1\",\r\n \"type\": \"string\"\r\n },\r\n {\r\n \"name\": \"s2\",\r\n \"type\": \"string\"\r\n },\r\n {\r\n \"name\": \"s3\",\r\n \"type\": \"string\"\r\n }\r\n ],\r\n \"return\": {\r\n \"type\": \"boolean\"\r\n }\r\n}",
|
||
|
"judgerAvailable": true,
|
||
|
"judgeType": "large",
|
||
|
"mysqlSchemas": [],
|
||
|
"enableRunCode": true,
|
||
|
"enableTestMode": false,
|
||
|
"enableDebugger": true,
|
||
|
"envInfo": "{\"cpp\": [\"C++\", \"<p>Compiled with <code> clang 11 </code> using the latest C++ 17 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level two optimization (<code>-O2</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\"], \"java\": [\"Java\", \"<p><code> OpenJDK 17 </code>. Java 8 features such as lambda expressions and stream API can be used. </p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n<p>Includes <code>Pair</code> class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.</p>\"], \"python\": [\"Python\", \"<p><code>Python 2.7.12</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/2/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/2/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/2/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\\r\\n\\r\\n<p>Note that Python 2.7 <a href=\\\"https://www.python.org/dev/peps/pep-0373/\\\" target=\\\"_blank\\\">will not be maintained past 2020</a>. For the latest Python, please choose Python3 instead.</p>\"], \"c\": [\"C\", \"<p>Compiled with <code>gcc 8.2</code> using the gnu99 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level one optimization (<code>-O1</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n\\r\\n<p>For hash table operations, you may use <a href=\\\"https://troydhanson.github.io/uthash/\\\" target=\\\"_blank\\\">uthash</a>. \\\"uthash.h\\\" is included by default. Below are some examples:</p>\\r\\n\\r\\n<p><b>1. Adding an item to a hash.</b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; /* we'll use this field as the key */\\r\\n char name[10];\\r\\n UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>2. Looking up an item in a hash:</b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>3. Deleting an item in a hash:</b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n</pre>\\r\\n</p>\"], \"csharp\": [\"C#\", \"<p><a href=\\\"https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9\\\" target=\\\"_blank\\\">C# 10 with .NET 6 runtime</a></p>\\r\\n\\r\\n<p>Your code is compiled with debug flag enabled (<code>/debug</code>).</p>\"], \"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use <a href=\\\"https://github.com/datastructures-js/priority-queue\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and <a href=\\\"https:
|
||
|
"libraryUrl": null,
|
||
|
"adminUrl": null,
|
||
|
"challengeQuestion": null,
|
||
|
"__typename": "QuestionNode"
|
||
|
}
|
||
|
}
|
||
|
}
|