mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-12-19 10:34:57 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>你正在设计一个动态数组。给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,其中 <code>nums[i]</code> 是 <code>i</code> 时刻数组中的元素数目。除此以外,你还有一个整数 <code>k</code> ,表示你可以 <strong>调整</strong> 数组大小的 <strong>最多</strong> 次数(每次都可以调整成 <strong>任意</strong> 大小)。</p>\n\n<p><code>t</code> 时刻数组的大小 <code>size<sub>t</sub></code> 必须大于等于 <code>nums[t]</code> ,因为数组需要有足够的空间容纳所有元素。<code>t</code> 时刻 <strong>浪费的空间</strong> 为 <code>size<sub>t</sub> - nums[t]</code> ,<strong>总</strong> 浪费空间为满足 <code>0 <= t < nums.length</code> 的每一个时刻 <code>t</code> 浪费的空间 <strong>之和</strong> 。</p>\n\n<p>在调整数组大小不超过 <code>k</code> 次的前提下,请你返回 <strong>最小总浪费空间</strong> 。</p>\n\n<p><strong>注意:</strong>数组最开始时可以为 <strong>任意大小</strong> ,且 <strong>不计入</strong> 调整大小的操作次数。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><b>输入:</b>nums = [10,20], k = 0\n<b>输出:</b>10\n<b>解释:</b>size = [20,20].\n我们可以让数组初始大小为 20 。\n总浪费空间为 (20 - 10) + (20 - 20) = 10 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><b>输入:</b>nums = [10,20,30], k = 1\n<b>输出:</b>10\n<b>解释:</b>size = [20,20,30].\n我们可以让数组初始大小为 20 ,然后时刻 2 调整大小为 30 。\n总浪费空间为 (20 - 10) + (20 - 20) + (30 - 30) = 10 。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><b>输入:</b>nums = [10,20,15,30,20], k = 2\n<b>输出:</b>15\n<b>解释:</b>size = [10,20,20,30,30].\n我们可以让数组初始大小为 10 ,时刻 1 调整大小为 20 ,时刻 3 调整大小为 30 。\n总浪费空间为 (10 - 10) + (20 - 20) + (20 - 15) + (30 - 30) + (30 - 20) = 15 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 200</code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>\n\t<li><code>0 <= k <= nums.length - 1</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 26,
|
||||
"likes": 27,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -143,7 +143,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"1.8K\", \"totalSubmission\": \"4.1K\", \"totalAcceptedRaw\": 1765, \"totalSubmissionRaw\": 4103, \"acRate\": \"43.0%\"}",
|
||||
"stats": "{\"totalAccepted\": \"1.8K\", \"totalSubmission\": \"4.2K\", \"totalAcceptedRaw\": 1806, \"totalSubmissionRaw\": 4193, \"acRate\": \"43.1%\"}",
|
||||
"hints": [
|
||||
"Given a range, how can you find the minimum waste if you can't perform any resize operations?",
|
||||
"Can we build our solution using dynamic programming using the current index and the number of resizing operations performed as the states?"
|
||||
|
||||
Reference in New Issue
Block a user