1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 05:26:46 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个下标从 <strong>0</strong>&nbsp;开始的字符串&nbsp;<code>text</code>&nbsp;和另一个下标从 <strong>0</strong>&nbsp;开始且长度为 <code>2</code>&nbsp;的字符串&nbsp;<code>pattern</code>&nbsp;,两者都只包含小写英文字母。</p>\n\n<p>你可以在 <code>text</code>&nbsp;中任意位置插入 <strong>一个</strong> 字符,这个插入的字符必须是&nbsp;<code>pattern[0]</code>&nbsp;<b>或者</b>&nbsp;<code>pattern[1]</code>&nbsp;。注意,这个字符可以插入在 <code>text</code>&nbsp;开头或者结尾的位置。</p>\n\n<p>请你返回插入一个字符后,<code>text</code>&nbsp;中最多包含多少个等于 <code>pattern</code>&nbsp;的 <strong>子序列</strong>&nbsp;。</p>\n\n<p><strong>子序列</strong> 指的是将一个字符串删除若干个字符后(也可以不删除),剩余字符保持原本顺序得到的字符串。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<b>输入:</b>text = \"abdcdbc\", pattern = \"ac\"\n<b>输出:</b>4\n<strong>解释:</strong>\n如果我们在 text[1] 和 text[2] 之间添加 pattern[0] = 'a' ,那么我们得到 \"ab<em><strong>a</strong></em>dcdbc\" 。那么 \"ac\" 作为子序列出现 4 次。\n其他得到 4 个 \"ac\" 子序列的方案还有 \"<em><strong>a</strong></em>abdcdbc\" 和 \"abd<em><strong>a</strong></em>cdbc\" 。\n但是\"abdc<em><strong>a</strong></em>dbc\" \"abd<em><strong>c</strong></em>cdbc\" 和 \"abdcdbc<em><strong>c</strong></em>\" 这些字符串虽然是可行的插入方案,但是只出现了 3 次 \"ac\" 子序列,所以不是最优解。\n可以证明插入一个字符后无法得到超过 4 个 \"ac\" 子序列。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<b>输入:</b>text = \"aabb\", pattern = \"ab\"\n<b>输出:</b>6\n<strong>解释:</strong>\n可以得到 6 个 \"ab\" 子序列的部分方案为 \"<em><strong>a</strong></em>aabb\" \"aa<em><strong>a</strong></em>bb\" 和 \"aab<em><strong>b</strong></em>b\" 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= text.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>pattern.length == 2</code></li>\n\t<li><code>text</code> 和&nbsp;<code>pattern</code>&nbsp;都只包含小写英文字母。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 11,
"likes": 12,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"4.8K\", \"totalSubmission\": \"16.6K\", \"totalAcceptedRaw\": 4821, \"totalSubmissionRaw\": 16625, \"acRate\": \"29.0%\"}",
"stats": "{\"totalAccepted\": \"5.2K\", \"totalSubmission\": \"17.7K\", \"totalAcceptedRaw\": 5208, \"totalSubmissionRaw\": 17705, \"acRate\": \"29.4%\"}",
"hints": [
"Find the optimal position to add pattern[0] so that the number of subsequences is maximized. Similarly, find the optimal position to add pattern[1].",
"For each of the above cases, count the number of times the pattern occurs as a subsequence in text. The larger count is the required answer."