1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-12-17 17:52:34 +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>多数元素</strong> 。</p>\n\n<p>子数组的 <strong>多数元素</strong> 是在子数组中出现&nbsp;<code>threshold</code>&nbsp;次数或次数以上的元素。</p>\n\n<p>实现 <code>MajorityChecker</code> 类:</p>\n\n<ul>\n\t<li><code>MajorityChecker(int[] arr)</code>&nbsp;会用给定的数组 <code>arr</code>&nbsp;对&nbsp;<code>MajorityChecker</code> 初始化。</li>\n\t<li><code>int query(int left, int right, int threshold)</code>&nbsp;返回子数组中的元素 &nbsp;<code>arr[left...right]</code>&nbsp;至少出现&nbsp;<code>threshold</code>&nbsp;次数,如果不存在这样的元素则返回 <code>-1</code>。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\n[\"MajorityChecker\", \"query\", \"query\", \"query\"]\n[[[1, 1, 2, 2, 1, 1]], [0, 5, 4], [0, 3, 3], [2, 3, 2]]\n<strong>输出:</strong>\n[null, 1, -1, 2]\n\n<b>解释:</b>\nMajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]);\nmajorityChecker.query(0,5,4); // 返回 1\nmajorityChecker.query(0,3,3); // 返回 -1\nmajorityChecker.query(2,3,2); // 返回 2\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= arr.length &lt;= 2 * 10<sup>4</sup></code></li>\n\t<li><code>1 &lt;= arr[i] &lt;= 2 * 10<sup>4</sup></code></li>\n\t<li><code>0 &lt;= left &lt;= right &lt; arr.length</code></li>\n\t<li><code>threshold &lt;= right - left + 1</code></li>\n\t<li><code>2 * threshold &gt; right - left + 1</code></li>\n\t<li>调用&nbsp;<code>query</code>&nbsp;的次数最多为&nbsp;<code>10<sup>4</sup></code>&nbsp;</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 60,
"likes": 61,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -161,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"3.4K\", \"totalSubmission\": \"10.4K\", \"totalAcceptedRaw\": 3432, \"totalSubmissionRaw\": 10404, \"acRate\": \"33.0%\"}",
"stats": "{\"totalAccepted\": \"3.5K\", \"totalSubmission\": \"10.5K\", \"totalAcceptedRaw\": 3499, \"totalSubmissionRaw\": 10527, \"acRate\": \"33.2%\"}",
"hints": [
"What's special about a majority element ?",
"A majority element appears more than half the length of the array number of times.",