mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-24 14:28:56 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个长桌子,桌子上盘子和蜡烛排成一列。给你一个下标从 <strong>0</strong> 开始的字符串 <code>s</code> ,它只包含字符 <code>'*'</code> 和 <code>'|'</code> ,其中 <code>'*'</code> 表示一个 <strong>盘子</strong> ,<code>'|'</code> 表示一支 <strong>蜡烛</strong> 。</p>\n\n<p>同时给你一个下标从 <strong>0</strong> 开始的二维整数数组 <code>queries</code> ,其中 <code>queries[i] = [left<sub>i</sub>, right<sub>i</sub>]</code> 表示 <strong>子字符串</strong> <code>s[left<sub>i</sub>...right<sub>i</sub>]</code> (<strong>包含左右端点的字符</strong>)。对于每个查询,你需要找到 <strong>子字符串中</strong> 在 <strong>两支蜡烛之间</strong> 的盘子的 <b>数目</b> 。如果一个盘子在 <strong>子字符串中</strong> 左边和右边 <strong>都</strong> 至少有一支蜡烛,那么这个盘子满足在 <strong>两支蜡烛之间</strong> 。</p>\n\n<ul>\n\t<li>比方说,<code>s = \"||**||**|*\"</code> ,查询 <code>[3, 8]</code> ,表示的是子字符串 <code>\"*||<strong><em>**</em></strong>|\"</code> 。子字符串中在两支蜡烛之间的盘子数目为 <code>2</code> ,子字符串中右边两个盘子在它们左边和右边 <strong>都 </strong>至少有一支蜡烛。</li>\n</ul>\n\n<p>请你返回一个整数数组 <code>answer</code> ,其中 <code>answer[i]</code> 是第 <code>i</code> 个查询的答案。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"ex-1\" src=\"https://assets.leetcode.com/uploads/2021/10/04/ex-1.png\" style=\"width: 400px; height: 134px;\"></p>\n\n<pre><b>输入:</b>s = \"**|**|***|\", queries = [[2,5],[5,9]]\n<b>输出:</b>[2,3]\n<b>解释:</b>\n- queries[0] 有两个盘子在蜡烛之间。\n- queries[1] 有三个盘子在蜡烛之间。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<p><img alt=\"ex-2\" src=\"https://assets.leetcode.com/uploads/2021/10/04/ex-2.png\" style=\"width: 600px; height: 193px;\"></p>\n\n<pre><b>输入:</b>s = \"***|**|*****|**||**|*\", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]]\n<b>输出:</b>[9,0,0,0,0]\n<strong>解释:</strong>\n- queries[0] 有 9 个盘子在蜡烛之间。\n- 另一个查询没有盘子在蜡烛之间。\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</code> 只包含字符 <code>'*'</code> 和 <code>'|'</code> 。</li>\n\t<li><code>1 <= queries.length <= 10<sup>5</sup></code></li>\n\t<li><code>queries[i].length == 2</code></li>\n\t<li><code>0 <= left<sub>i</sub> <= right<sub>i</sub> < s.length</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 141,
|
||||
"likes": 144,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"31.3K\", \"totalSubmission\": \"72.5K\", \"totalAcceptedRaw\": 31343, \"totalSubmissionRaw\": 72547, \"acRate\": \"43.2%\"}",
|
||||
"stats": "{\"totalAccepted\": \"31.7K\", \"totalSubmission\": \"73.3K\", \"totalAcceptedRaw\": 31698, \"totalSubmissionRaw\": 73296, \"acRate\": \"43.2%\"}",
|
||||
"hints": [
|
||||
"Can you find the indices of the most left and right candles for a given substring, perhaps by using binary search (or better) over an array of indices of all the bars?",
|
||||
"Once the indices of the most left and right bars are determined, how can you efficiently count the number of plates within the range? Prefix sums?"
|
||||
|
||||
Reference in New Issue
Block a user