mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 23:11:41 +08:00
update
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2325",
|
||||
"questionFrontendId": "6035",
|
||||
"questionFrontendId": "2222",
|
||||
"categoryTitle": "Algorithms",
|
||||
"boundTopicId": 1385553,
|
||||
"title": "Number of Ways to Select Buildings",
|
||||
@@ -12,13 +12,32 @@
|
||||
"translatedContent": "<p>给你一个下标从 <strong>0</strong> 开始的二进制字符串 <code>s</code> ,它表示一条街沿途的建筑类型,其中:</p>\n\n<ul>\n\t<li><code>s[i] = '0'</code> 表示第 <code>i</code> 栋建筑是一栋办公楼,</li>\n\t<li><code>s[i] = '1'</code> 表示第 <code>i</code> 栋建筑是一间餐厅。</li>\n</ul>\n\n<p>作为市政厅的官员,你需要随机<strong> 选择</strong> 3 栋建筑。然而,为了确保多样性,选出来的 3 栋建筑 <strong>相邻</strong> 的两栋不能是同一类型。</p>\n\n<ul>\n\t<li>比方说,给你 <code>s = \"0<em><strong>0</strong></em>1<em><strong>1</strong></em>0<em><strong>1</strong></em>\"</code> ,我们不能选择第 <code>1</code> ,<code>3</code> 和 <code>5</code> 栋建筑,因为得到的子序列是 <code>\"0<em><strong>11</strong></em>\"</code> ,有相邻两栋建筑是同一类型,所以 <strong>不合</strong> 题意。</li>\n</ul>\n\n<p>请你返回可以选择 3 栋建筑的 <strong>有效方案数</strong> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><b>输入:</b>s = \"001101\"\n<b>输出:</b>6\n<b>解释:</b>\n以下下标集合是合法的:\n- [0,2,4] ,从 \"<em><strong>0</strong></em>0<em><strong>1</strong></em>1<em><strong>0</strong></em>1\" 得到 \"010\"\n- [0,3,4] ,从 \"<em><strong>0</strong></em>01<em><strong>10</strong></em>1\" 得到 \"010\"\n- [1,2,4] ,从 \"0<em><strong>01</strong></em>1<em><strong>0</strong></em>1\" 得到 \"010\"\n- [1,3,4] ,从 \"0<em><strong>0</strong></em>1<em><strong>10</strong></em>1\" 得到 \"010\"\n- [2,4,5] ,从 \"00<em><strong>1</strong></em>1<em><strong>01</strong></em>\" 得到 \"101\"\n- [3,4,5] ,从 \"001<em><strong>101</strong></em>\" 得到 \"101\"\n没有别的合法选择,所以总共有 6 种方法。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><b>输入:</b>s = \"11100\"\n<b>输出:</b>0\n<b>解释:</b>没有任何符合题意的选择。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>3 <= s.length <= 10<sup>5</sup></code></li>\n\t<li><code>s[i]</code> 要么是 <code>'0'</code> ,要么是 <code>'1'</code> 。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 10,
|
||||
"likes": 18,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}",
|
||||
"topicTags": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "String",
|
||||
"slug": "string",
|
||||
"translatedName": "字符串",
|
||||
"__typename": "TopicTagNode"
|
||||
},
|
||||
{
|
||||
"name": "Dynamic Programming",
|
||||
"slug": "dynamic-programming",
|
||||
"translatedName": "动态规划",
|
||||
"__typename": "TopicTagNode"
|
||||
},
|
||||
{
|
||||
"name": "Prefix Sum",
|
||||
"slug": "prefix-sum",
|
||||
"translatedName": "前缀和",
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
@@ -130,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"3.1K\", \"totalSubmission\": \"7.2K\", \"totalAcceptedRaw\": 3098, \"totalSubmissionRaw\": 7196, \"acRate\": \"43.1%\"}",
|
||||
"stats": "{\"totalAccepted\": \"4.3K\", \"totalSubmission\": \"9.3K\", \"totalAcceptedRaw\": 4324, \"totalSubmissionRaw\": 9346, \"acRate\": \"46.3%\"}",
|
||||
"hints": [
|
||||
"There are only 2 valid patterns: ‘101’ and ‘010’. Think about how we can construct these 2 patterns from smaller patterns.",
|
||||
"Count the number of subsequences of the form ‘01’ or ‘10’ first. Let n01[i] be the number of ‘01’ subsequences that exist in the prefix of s up to the ith building. How can you compute n01[i]?",
|
||||
|
Reference in New Issue
Block a user