mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-02 22:13:28 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个数组 <code>points</code> 和一个整数 <code>k</code> 。数组中每个元素都表示二维平面上的点的坐标,并按照横坐标 x 的值从小到大排序。也就是说 <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> ,并且在 <code>1 <= i < j <= points.length</code> 的前提下, <code>x<sub>i</sub> < x<sub>j</sub></code> 总成立。</p>\n\n<p>请你找出<em> </em><code>y<sub>i</sub> + y<sub>j</sub> + |x<sub>i</sub> - x<sub>j</sub>|</code> 的 <strong>最大值</strong>,其中 <code>|x<sub>i</sub> - x<sub>j</sub>| <= k</code> 且 <code>1 <= i < j <= points.length</code>。</p>\n\n<p>题目测试数据保证至少存在一对能够满足 <code>|x<sub>i</sub> - x<sub>j</sub>| <= k</code> 的点。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>points = [[1,3],[2,0],[5,10],[6,-10]], k = 1\n<strong>输出:</strong>4\n<strong>解释:</strong>前两个点满足 |x<sub>i</sub> - x<sub>j</sub>| <= 1 ,代入方程计算,则得到值 3 + 0 + |1 - 2| = 4 。第三个和第四个点也满足条件,得到值 10 + -10 + |5 - 6| = 1 。\n没有其他满足条件的点,所以返回 4 和 1 中最大的那个。</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>points = [[0,0],[3,0],[9,2]], k = 3\n<strong>输出:</strong>3\n<strong>解释:</strong>只有前两个点满足 |x<sub>i</sub> - x<sub>j</sub>| <= 3 ,代入方程后得到值 0 + 0 + |0 - 3| = 3 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 <= points.length <= 10^5</code></li>\n\t<li><code>points[i].length == 2</code></li>\n\t<li><code>-10^8 <= points[i][0], points[i][1] <= 10^8</code></li>\n\t<li><code>0 <= k <= 2 * 10^8</code></li>\n\t<li>对于所有的<code>1 <= i < j <= points.length</code> ,<code>points[i][0] < points[j][0]</code> 都成立。也就是说,<code>x<sub>i</sub></code> 是严格递增的。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 51,
|
||||
"likes": 54,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -161,7 +161,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"3.3K\", \"totalSubmission\": \"8.6K\", \"totalAcceptedRaw\": 3315, \"totalSubmissionRaw\": 8614, \"acRate\": \"38.5%\"}",
|
||||
"stats": "{\"totalAccepted\": \"3.4K\", \"totalSubmission\": \"8.9K\", \"totalAcceptedRaw\": 3412, \"totalSubmissionRaw\": 8885, \"acRate\": \"38.4%\"}",
|
||||
"hints": [
|
||||
"Use a priority queue to store for each point i, the tuple [yi-xi, xi]",
|
||||
"Loop through the array and pop elements from the heap if the condition xj - xi > k, where j is the current index and i is the point on top the queue.",
|
||||
|
Reference in New Issue
Block a user