1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-05 23:41:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-03-29 16:56:27 +08:00
parent e730aa6794
commit ad15da05aa
2517 changed files with 7358 additions and 7332 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个房屋数组<code>houses</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;,其中&nbsp;<code>houses[i]</code>&nbsp;是第 <code>i</code>&nbsp;栋房子在一条街上的位置,现需要在这条街上安排 <code>k</code>&nbsp;个邮筒。</p>\n\n<p>请你返回每栋房子与离它最近的邮筒之间的距离的 <strong>最小 </strong>总和。</p>\n\n<p>答案保证在 32 位有符号整数范围以内。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/06/13/sample_11_1816.png\" style=\"height: 154px; width: 454px;\"></p>\n\n<pre><strong>输入:</strong>houses = [1,4,8,10,20], k = 3\n<strong>输出:</strong>5\n<strong>解释:</strong>将邮筒分别安放在位置 3 9 和 20 处。\n每个房子到最近邮筒的距离和为 |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/06/13/sample_2_1816.png\" style=\"height: 154px; width: 433px;\"></strong></p>\n\n<pre><strong>输入:</strong>houses = [2,3,5,12,18], k = 2\n<strong>输出:</strong>9\n<strong>解释:</strong>将邮筒分别安放在位置 3 和 14 处。\n每个房子到最近邮筒距离和为 |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9 。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><strong>输入:</strong>houses = [7,4,6,1], k = 1\n<strong>输出:</strong>8\n</pre>\n\n<p><strong>示例 4</strong></p>\n\n<pre><strong>输入:</strong>houses = [3,6,14,10], k = 4\n<strong>输出:</strong>0\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == houses.length</code></li>\n\t<li><code>1 &lt;= n&nbsp;&lt;= 100</code></li>\n\t<li><code>1 &lt;= houses[i] &lt;= 10^4</code></li>\n\t<li><code>1 &lt;= k &lt;= n</code></li>\n\t<li>数组&nbsp;<code>houses</code>&nbsp;中的整数互不相同。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 77,
"likes": 78,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"3.4K\", \"totalSubmission\": \"5.7K\", \"totalAcceptedRaw\": 3377, \"totalSubmissionRaw\": 5672, \"acRate\": \"59.5%\"}",
"stats": "{\"totalAccepted\": \"3.4K\", \"totalSubmission\": \"5.7K\", \"totalAcceptedRaw\": 3387, \"totalSubmissionRaw\": 5684, \"acRate\": \"59.6%\"}",
"hints": [
"If k =1, the minimum distance is obtained allocating the mailbox in the median of the array houses.",
"Generalize this idea, using dynamic programming allocating k mailboxes."