mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 16:01:41 +08:00
批量更新数据
This commit is contained in:
@@ -7,17 +7,17 @@
|
||||
"boundTopicId": 2267105,
|
||||
"title": "Chunk Array",
|
||||
"titleSlug": "chunk-array",
|
||||
"content": "<p>Given an array <code>arr</code> and a chunk size <code>size</code>, return a <strong>chunked</strong> array. A <strong>chunked</strong> array contains the original elements in <code>arr</code>, but consists of subarrays each of length <code>size</code>. The length of the last subarray may be less than <code>size</code> if <code>arr.length</code> is not evenly divisible by <code>size</code>.</p>\n\n<p>You may assume the array is the output of <code>JSON.parse</code>. In other words, it is valid JSON.</p>\n\n<p>Please solve it without using lodash's <code>_.chunk</code> function.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,2,3,4,5], size = 1\n<strong>Output:</strong> [[1],[2],[3],[4],[5]]\n<strong>Explanation:</strong> The arr has been split into subarrays each with 1 element.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,9,6,3,2], size = 3\n<strong>Output:</strong> [[1,9,6],[3,2]]\n<strong>Explanation:</strong> The arr has been split into subarrays with 3 elements. However, only two elements are left for the 2nd subarray.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [8,5,3,2,6], size = 6\n<strong>Output:</strong> [[8,5,3,2,6]]\n<strong>Explanation:</strong> Size is greater than arr.length thus all elements are in the first subarray.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [], size = 1\n<strong>Output:</strong> []\n<strong>Explanation:</strong> There are no elements to be chunked so an empty array is returned.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>arr</code> is a valid JSON array</li>\n\t<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= size <= arr.length + 1</code></li>\n</ul>\n",
|
||||
"content": "<p>Given an array <code>arr</code> and a chunk size <code>size</code>, return a <strong>chunked</strong> array.</p>\n\n<p>A <strong>chunked</strong> array contains the original elements in <code>arr</code>, but consists of subarrays each of length <code>size</code>. The length of the last subarray may be less than <code>size</code> if <code>arr.length</code> is not evenly divisible by <code>size</code>.</p>\n\n<p>You may assume the array is the output of <code>JSON.parse</code>. In other words, it is valid JSON.</p>\n\n<p>Please solve it without using lodash's <code>_.chunk</code> function.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,2,3,4,5], size = 1\n<strong>Output:</strong> [[1],[2],[3],[4],[5]]\n<strong>Explanation:</strong> The arr has been split into subarrays each with 1 element.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,9,6,3,2], size = 3\n<strong>Output:</strong> [[1,9,6],[3,2]]\n<strong>Explanation:</strong> The arr has been split into subarrays with 3 elements. However, only two elements are left for the 2nd subarray.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [8,5,3,2,6], size = 6\n<strong>Output:</strong> [[8,5,3,2,6]]\n<strong>Explanation:</strong> Size is greater than arr.length thus all elements are in the first subarray.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [], size = 1\n<strong>Output:</strong> []\n<strong>Explanation:</strong> There are no elements to be chunked so an empty array is returned.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>arr</code> is a valid JSON array</li>\n\t<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= size <= arr.length + 1</code></li>\n</ul>\n",
|
||||
"translatedTitle": "分块数组",
|
||||
"translatedContent": "<p>给定一个数组 <code>arr</code> 和一个块大小 <code>size</code> ,返回一个 <strong>分块</strong> 的数组。<strong>分块</strong> 的数组包含了 <code>arr</code> 中的原始元素,但是每个子数组的长度都是 <code>size</code> 。如果 <code>arr.length</code> 不能被 <code>size</code> 整除,那么最后一个子数组的长度可能小于 <code>size</code> 。</p>\n\n<p>你可以假设该数组是 <code>JSON.parse</code> 的输出结果。换句话说,它是有效的JSON。</p>\n\n<p>请你在不使用 lodash 的函数 <code>_.chunk</code> 的情况下解决这个问题。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [1,2,3,4,5], size = 1\n<b>输出:</b>[[1],[2],[3],[4],[5]]\n<b>解释:</b>数组 <code>arr </code>被分割成了每个只有一个元素的子数组。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [1,9,6,3,2], size = 3\n<b>输出:</b>[[1,9,6],[3,2]]\n<b>解释:</b>数组 <code>arr </code>被分割成了每个有三个元素的子数组。然而,第二个子数组只有两个元素。\n</pre>\n\n<p><strong class=\"example\">示例 3:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [8,5,3,2,6], size = 6\n<b>输出:</b>[[8,5,3,2,6]]\n<b>解释:</b><code>size </code>大于 <code>arr.length </code>,因此所有元素都在第一个子数组中。\n</pre>\n\n<p><strong class=\"example\">示例 4:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [], size = 1\n<b>输出:</b>[]\n<b>解释:</b>没有元素需要分块,因此返回一个空数组。</pre>\n\n<p> </p>\n\n<p><b>提示:</b></p>\n\n<ul>\n\t<li><code>arr</code> 是一个有效的 JSON 数组</li>\n\t<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= size <= arr.length + 1</code></li>\n</ul>\n",
|
||||
"translatedContent": "<p>给定一个数组 <code>arr</code> 和一个块大小 <code>size</code> ,返回一个 <strong>分块</strong> 的数组。</p>\n\n<p><strong>分块</strong> 的数组包含了 <code>arr</code> 中的原始元素,但是每个子数组的长度都是 <code>size</code> 。如果 <code>arr.length</code> 不能被 <code>size</code> 整除,那么最后一个子数组的长度可能小于 <code>size</code> 。</p>\n\n<p>你可以假设该数组是 <code>JSON.parse</code> 的输出结果。换句话说,它是有效的JSON。</p>\n\n<p>请你在不使用 lodash 的函数 <code>_.chunk</code> 的情况下解决这个问题。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [1,2,3,4,5], size = 1\n<b>输出:</b>[[1],[2],[3],[4],[5]]\n<b>解释:</b>数组 <code>arr </code>被分割成了每个只有一个元素的子数组。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [1,9,6,3,2], size = 3\n<b>输出:</b>[[1,9,6],[3,2]]\n<b>解释:</b>数组 <code>arr </code>被分割成了每个有三个元素的子数组。然而,第二个子数组只有两个元素。\n</pre>\n\n<p><strong class=\"example\">示例 3:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [8,5,3,2,6], size = 6\n<b>输出:</b>[[8,5,3,2,6]]\n<b>解释:</b><code>size </code>大于 <code>arr.length </code>,因此所有元素都在第一个子数组中。\n</pre>\n\n<p><strong class=\"example\">示例 4:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [], size = 1\n<b>输出:</b>[]\n<b>解释:</b>没有元素需要分块,因此返回一个空数组。</pre>\n\n<p> </p>\n\n<p><b>提示:</b></p>\n\n<ul>\n\t<li><code>arr</code> 是一个有效的 JSON 数组</li>\n\t<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= size <= arr.length + 1</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 5,
|
||||
"likes": 7,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
|
||||
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false, \"cangjie\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
@@ -30,11 +30,11 @@
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };\ntype Obj = Record<string, JSONValue> | Array<JSONValue>;\n\nfunction chunk(arr: Obj[], size: number): Obj[][] {\n\t\n};",
|
||||
"code": "type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };\ntype Obj = Record<string, JSONValue> | Array<JSONValue>;\n\nfunction chunk(arr: Obj[], size: number): Obj[][] {\n \n};",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"4.5K\", \"totalSubmission\": \"6.1K\", \"totalAcceptedRaw\": 4503, \"totalSubmissionRaw\": 6145, \"acRate\": \"73.3%\"}",
|
||||
"stats": "{\"totalAccepted\": \"7.9K\", \"totalSubmission\": \"10.3K\", \"totalAcceptedRaw\": 7894, \"totalSubmissionRaw\": 10270, \"acRate\": \"76.9%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
@@ -44,7 +44,7 @@
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 20.10.0<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/blob\\/v5\\/README.md\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.4.0<\\/a>\\uff0c<a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/v4.2.3\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.3<\\/a> \\u4ee5\\u53ca <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/deque\\/tree\\/v1.0.4\\\" target=\\\"_blank\\\"> datastructures-js\\/deque@1.0.4<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/blob\\/v5\\/README.md\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.4.0<\\/a>\\uff0c<a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/v4.2.3\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.3<\\/a> \\u4ee5\\u53ca <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/deque\\/tree\\/v1.0.4\\\" target=\\\"_blank\\\"> datastructures-js\\/deque@1.0.4<\\/a>\\u3002<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
|
Reference in New Issue
Block a user