1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-21 21:16:45 +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>给你一个在 X-Y 平面上的点构成的数据流。设计一个满足下述要求的算法:</p>\n\n<ul>\n\t<li><strong>添加</strong> 一个在数据流中的新点到某个数据结构中<strong>。</strong>可以添加 <strong>重复</strong> 的点,并会视作不同的点进行处理。</li>\n\t<li>给你一个查询点,请你从数据结构中选出三个点,使这三个点和查询点一同构成一个 <strong>面积为正</strong> 的 <strong>轴对齐正方形</strong> <strong>统计</strong> 满足该要求的方案数目<strong>。</strong></li>\n</ul>\n\n<p><strong>轴对齐正方形</strong> 是一个正方形,除四条边长度相同外,还满足每条边都与 x-轴 或 y-轴 平行或垂直。</p>\n\n<p>实现 <code>DetectSquares</code> 类:</p>\n\n<ul>\n\t<li><code>DetectSquares()</code> 使用空数据结构初始化对象</li>\n\t<li><code>void add(int[] point)</code> 向数据结构添加一个新的点 <code>point = [x, y]</code></li>\n\t<li><code>int count(int[] point)</code> 统计按上述方式与点 <code>point = [x, y]</code> 共同构造 <strong>轴对齐正方形</strong> 的方案数。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>示例:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/01/image.png\" style=\"width: 869px; height: 504px;\" />\n<pre>\n<strong>输入:</strong>\n[\"DetectSquares\", \"add\", \"add\", \"add\", \"count\", \"count\", \"add\", \"count\"]\n[[], [[3, 10]], [[11, 2]], [[3, 2]], [[11, 10]], [[14, 8]], [[11, 2]], [[11, 10]]]\n<strong>输出:</strong>\n[null, null, null, null, 1, 0, null, 2]\n\n<strong>解释:</strong>\nDetectSquares detectSquares = new DetectSquares();\ndetectSquares.add([3, 10]);\ndetectSquares.add([11, 2]);\ndetectSquares.add([3, 2]);\ndetectSquares.count([11, 10]); // 返回 1 。你可以选择:\n // - 第一个,第二个,和第三个点\ndetectSquares.count([14, 8]); // 返回 0 。查询点无法与数据结构中的这些点构成正方形。\ndetectSquares.add([11, 2]); // 允许添加重复的点。\ndetectSquares.count([11, 10]); // 返回 2 。你可以选择:\n // - 第一个,第二个,和第三个点\n // - 第一个,第三个,和第四个点\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>point.length == 2</code></li>\n\t<li><code>0 &lt;= x, y &lt;= 1000</code></li>\n\t<li>调用&nbsp;<code>add</code> 和 <code>count</code> 的 <strong>总次数</strong> 最多为 <code>5000</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 106,
"likes": 107,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"19.6K\", \"totalSubmission\": \"34.7K\", \"totalAcceptedRaw\": 19638, \"totalSubmissionRaw\": 34681, \"acRate\": \"56.6%\"}",
"stats": "{\"totalAccepted\": \"19.8K\", \"totalSubmission\": \"35K\", \"totalAcceptedRaw\": 19780, \"totalSubmissionRaw\": 34967, \"acRate\": \"56.6%\"}",
"hints": [
"Maintain the frequency of all the points in a hash map.",
"Traverse the hash map and if any point has the same y-coordinate as the query point, consider this point and the query point to form one of the horizontal lines of the square."