1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-02 14:12:17 +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>给你一个整数数组 <code>nums</code> 和一个整数 <code>x</code> 。每一次操作时,你应当移除数组 <code>nums</code> 最左边或最右边的元素,然后从 <code>x</code> 中减去该元素的值。请注意,需要 <strong>修改</strong> 数组以供接下来的操作使用。</p>\n\n<p>如果可以将 <code>x</code> <strong>恰好</strong> 减到 <code>0</code> ,返回<strong> 最小操作数 </strong>;否则,返回 <code>-1</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,1,4,2,3], x = 5\n<strong>输出:</strong>2\n<strong>解释:</strong>最佳解决方案是移除后两个元素,将 x 减到 0 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [5,6,7,8,9], x = 4\n<strong>输出:</strong>-1\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [3,2,20,1,1,3], x = 10\n<strong>输出:</strong>5\n<strong>解释:</strong>最佳解决方案是移除后三个元素和前两个元素(总共 5 次操作),将 x 减到 0 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>\n\t<li><code>1 <= x <= 10<sup>9</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 90,
"likes": 97,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -161,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"11.4K\", \"totalSubmission\": \"36.6K\", \"totalAcceptedRaw\": 11437, \"totalSubmissionRaw\": 36622, \"acRate\": \"31.2%\"}",
"stats": "{\"totalAccepted\": \"11.9K\", \"totalSubmission\": \"37.9K\", \"totalAcceptedRaw\": 11854, \"totalSubmissionRaw\": 37923, \"acRate\": \"31.3%\"}",
"hints": [
"Think in reverse; instead of finding the minimum prefix + suffix, find the maximum subarray.",
"Finding the maximum subarray is standard and can be done greedily."