mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-12-17 17:52:34 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>设计一个数据结构,有效地找到给定子数组的 <strong>多数元素</strong> 。</p>\n\n<p>子数组的 <strong>多数元素</strong> 是在子数组中出现 <code>threshold</code> 次数或次数以上的元素。</p>\n\n<p>实现 <code>MajorityChecker</code> 类:</p>\n\n<ul>\n\t<li><code>MajorityChecker(int[] arr)</code> 会用给定的数组 <code>arr</code> 对 <code>MajorityChecker</code> 初始化。</li>\n\t<li><code>int query(int left, int right, int threshold)</code> 返回子数组中的元素 <code>arr[left...right]</code> 至少出现 <code>threshold</code> 次数,如果不存在这样的元素则返回 <code>-1</code>。</li>\n</ul>\n\n<p> </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> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr.length <= 2 * 10<sup>4</sup></code></li>\n\t<li><code>1 <= arr[i] <= 2 * 10<sup>4</sup></code></li>\n\t<li><code>0 <= left <= right < arr.length</code></li>\n\t<li><code>threshold <= right - left + 1</code></li>\n\t<li><code>2 * threshold > right - left + 1</code></li>\n\t<li>调用 <code>query</code> 的次数最多为 <code>10<sup>4</sup></code> </li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 58,
|
||||
"likes": 60,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -161,7 +161,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"3.4K\", \"totalSubmission\": \"10.4K\", \"totalAcceptedRaw\": 3429, \"totalSubmissionRaw\": 10400, \"acRate\": \"33.0%\"}",
|
||||
"stats": "{\"totalAccepted\": \"3.4K\", \"totalSubmission\": \"10.4K\", \"totalAcceptedRaw\": 3432, \"totalSubmissionRaw\": 10404, \"acRate\": \"33.0%\"}",
|
||||
"hints": [
|
||||
"What's special about a majority element ?",
|
||||
"A majority element appears more than half the length of the array number of times.",
|
||||
|
||||
Reference in New Issue
Block a user