mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 23:41:41 +08:00
存量题库数据更新
This commit is contained in:
@@ -6,13 +6,13 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Join Two Arrays by ID",
|
||||
"titleSlug": "join-two-arrays-by-id",
|
||||
"content": "<p>Given two arrays <code>arr1</code> and <code>arr2</code>, return a new array <code>joinedArray</code>. All the objects in each of the two inputs arrays will contain an <code>id</code> field that has an integer value. <code>joinedArray</code> is an array formed by merging <code>arr1</code> and <code>arr2</code> based on their <code>id</code> key. The length of <code>joinedArray</code> should be the length of unique values of <code>id</code>. The returned array should be sorted in <strong>ascending</strong> order based on the <code>id</code> key.</p>\n\n<p>If a given <code>id</code> exists in one array but not the other, the single object with that <code>id</code> should be included in the result array without modification.</p>\n\n<p>If two objects share an <code>id</code>, their properties should be merged into a single object:</p>\n\n<ul>\n\t<li>If a key only exists in one object, that single key-value pair should be included in the object.</li>\n\t<li>If a key is included in both objects, the value in the object from <code>arr2</code> should override the value from <code>arr1</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr1 = [\n {"id": 1, "x": 1},\n {"id": 2, "x": 9}\n], \narr2 = [\n {"id": 3, "x": 5}\n]\n<strong>Output:</strong> \n[\n {"id": 1, "x": 1},\n {"id": 2, "x": 9},\n {"id": 3, "x": 5}\n]\n<strong>Explanation:</strong> There are no duplicate ids so arr1 is simply concatenated with arr2.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr1 = [\n {"id": 1, "x": 2, "y": 3},\n {"id": 2, "x": 3, "y": 6}\n], \narr2 = [\n {"id": 2, "x": 10, "y": 20},\n {"id": 3, "x": 0, "y": 0}\n]\n<strong>Output:</strong> \n[\n {"id": 1, "x": 2, "y": 3},\n {"id": 2, "x": 10, "y": 20},\n {"id": 3, "x": 0, "y": 0}\n]\n<strong>Explanation:</strong> The two objects with id=1 and id=3 are included in the result array without modifiction. The two objects with id=2 are merged together. The keys from arr2 override the values in arr1.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr1 = [\n {"id": 1, "b": {"b": 94},"v": [4, 3], "y": 48}\n]\narr2 = [\n {"id": 1, "b": {"c": 84}, "v": [1, 3]}\n]\n<strong>Output:</strong> [\n {"id": 1, "b": {"c": 84}, "v": [1, 3], "y": 48}\n]\n<strong>Explanation:</strong> The two objects with id=1 are merged together. For the keys "b" and "v" the values from arr2 are used. Since the key "y" only exists in arr1, that value is taken form arr1.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>arr1 and arr2 are valid JSON arrays</code></li>\n\t<li><code>Each object in arr1 and arr2 has a unique integer id key</code></li>\n\t<li><code>2 <= JSON.stringify(arr1).length <= 10<sup>6</sup></code></li>\n\t<li><code>2 <= JSON.stringify(arr2).length <= 10<sup>6</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>Given two arrays <code>arr1</code> and <code>arr2</code>, return a new array <code>joinedArray</code>. All the objects in each of the two inputs arrays will contain an <code>id</code> field that has an integer value. <code>joinedArray</code> is an array formed by merging <code>arr1</code> and <code>arr2</code> based on their <code>id</code> key. The length of <code>joinedArray</code> should be the length of unique values of <code>id</code>. The returned array should be sorted in <strong>ascending</strong> order based on the <code>id</code> key.</p>\n\n<p>If a given <code>id</code> exists in one array but not the other, the single object with that <code>id</code> should be included in the result array without modification.</p>\n\n<p>If two objects share an <code>id</code>, their properties should be merged into a single object:</p>\n\n<ul>\n\t<li>If a key only exists in one object, that single key-value pair should be included in the object.</li>\n\t<li>If a key is included in both objects, the value in the object from <code>arr2</code> should override the value from <code>arr1</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr1 = [\n {"id": 1, "x": 1},\n {"id": 2, "x": 9}\n], \narr2 = [\n {"id": 3, "x": 5}\n]\n<strong>Output:</strong> \n[\n {"id": 1, "x": 1},\n {"id": 2, "x": 9},\n {"id": 3, "x": 5}\n]\n<strong>Explanation:</strong> There are no duplicate ids so arr1 is simply concatenated with arr2.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr1 = [\n {"id": 1, "x": 2, "y": 3},\n {"id": 2, "x": 3, "y": 6}\n], \narr2 = [\n {"id": 2, "x": 10, "y": 20},\n {"id": 3, "x": 0, "y": 0}\n]\n<strong>Output:</strong> \n[\n {"id": 1, "x": 2, "y": 3},\n {"id": 2, "x": 10, "y": 20},\n {"id": 3, "x": 0, "y": 0}\n]\n<strong>Explanation:</strong> The two objects with id=1 and id=3 are included in the result array without modifiction. The two objects with id=2 are merged together. The keys from arr2 override the values in arr1.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr1 = [\n {"id": 1, "b": {"b": 94},"v": [4, 3], "y": 48}\n]\narr2 = [\n {"id": 1, "b": {"c": 84}, "v": [1, 3]}\n]\n<strong>Output:</strong> [\n {"id": 1, "b": {"c": 84}, "v": [1, 3], "y": 48}\n]\n<strong>Explanation:</strong> The two objects with id=1 are merged together. For the keys "b" and "v" the values from arr2 are used. Since the key "y" only exists in arr1, that value is taken form arr1.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>arr1</code> and <code>arr2</code> are valid JSON arrays</li>\n\t<li>Each object in <code>arr1</code> and <code>arr2</code> has a unique integer <code>id</code> key</li>\n\t<li><code>2 <= JSON.stringify(arr1).length <= 10<sup>6</sup></code></li>\n\t<li><code>2 <= JSON.stringify(arr2).length <= 10<sup>6</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 13,
|
||||
"dislikes": 3,
|
||||
"likes": 111,
|
||||
"dislikes": 40,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "[{\"id\": 1,\"x\": 1},{\"id\": 2,\"x\": 9}]\n[{\"id\": 3,\"x\": 5}]\n[{\"id\": 1,\"x\": 2,\"y\": 3},{\"id\": 2,\"x\": 3,\"y\": 6}]\n[{\"id\": 2,\"x\": 10,\"y\": 20},{\"id\": 3,\"x\": 0,\"y\": 0}]\n[{\"id\":1,\"b\":{\"b\": 94},\"v\":[4,3],\"y\":48}]\n[{\"id\":1,\"b\":{\"c\": 84},\"v\":[1,3]}]",
|
||||
@@ -30,13 +30,20 @@
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function join(arr1: any[], arr2: any[]): any[] {\n\n};",
|
||||
"code": "type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };\n\nfunction join(arr1: JSONValue[], arr2: JSONValue[]): JSONValue[] {\n\t\n};",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"571\", \"totalSubmission\": \"880\", \"totalAcceptedRaw\": 571, \"totalSubmissionRaw\": 880, \"acRate\": \"64.9%\"}",
|
||||
"stats": "{\"totalAccepted\": \"12.1K\", \"totalSubmission\": \"22.9K\", \"totalAcceptedRaw\": 12114, \"totalSubmissionRaw\": 22880, \"acRate\": \"52.9%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"solution": {
|
||||
"id": "1996",
|
||||
"canSeeDetail": true,
|
||||
"paidOnly": false,
|
||||
"hasVideoSolution": false,
|
||||
"paidOnlyVideo": true,
|
||||
"__typename": "ArticleNode"
|
||||
},
|
||||
"status": null,
|
||||
"sampleTestCase": "[{\"id\": 1,\"x\": 1},{\"id\": 2,\"x\": 9}]\n[{\"id\": 3,\"x\": 5}]",
|
||||
"metaData": "{\n \"name\": \"join\",\n \"params\": [\n {\n \"name\": \"arr1\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"arr2\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
@@ -46,7 +53,7 @@
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 5.1.6, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2022 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
|
Reference in New Issue
Block a user