1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-02-04 14:40:27 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/originData/earliest-second-to-mark-indices-ii.json
2024-03-01 00:47:37 +08:00

188 lines
29 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"data": {
"question": {
"questionId": "3289",
"questionFrontendId": "3049",
"categoryTitle": "Algorithms",
"boundTopicId": 2650520,
"title": "Earliest Second to Mark Indices II",
"titleSlug": "earliest-second-to-mark-indices-ii",
"content": "<p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>\n\n<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>\n\n<p>In each second, <code>s</code>, in order from <code>1</code> to <code>m</code> (<strong>inclusive</strong>), you can perform <strong>one</strong> of the following operations:</p>\n\n<ul>\n\t<li>Choose an index <code>i</code> in the range <code>[1, n]</code> and <strong>decrement</strong> <code>nums[i]</code> by <code>1</code>.</li>\n\t<li>Set <code>nums[changeIndices[s]]</code> to any <strong>non-negative</strong> value.</li>\n\t<li>Choose an index <code>i</code> in the range <code>[1, n]</code>, where <code>nums[i]</code> is <strong>equal</strong> to <code>0</code>, and <strong>mark</strong> index <code>i</code>.</li>\n\t<li>Do nothing.</li>\n</ul>\n\n<p>Return <em>an integer denoting the <strong>earliest second</strong> in the range </em><code>[1, m]</code><em> when <strong>all</strong> indices in </em><code>nums</code><em> can be marked by choosing operations optimally, or </em><code>-1</code><em> if it is impossible.</em></p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,2,3], changeIndices = [1,3,2,2,2,2,3]\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> In this example, we have 7 seconds. The following operations can be performed to mark all indices:\nSecond 1: Set nums[changeIndices[1]] to 0. nums becomes [0,2,3].\nSecond 2: Set nums[changeIndices[2]] to 0. nums becomes [0,2,0].\nSecond 3: Set nums[changeIndices[3]] to 0. nums becomes [0,0,0].\nSecond 4: Mark index 1, since nums[1] is equal to 0.\nSecond 5: Mark index 2, since nums[2] is equal to 0.\nSecond 6: Mark index 3, since nums[3] is equal to 0.\nNow all indices have been marked.\nIt can be shown that it is not possible to mark all indices earlier than the 6th second.\nHence, the answer is 6.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,0,1,2], changeIndices = [1,2,1,2,1,2,1,2]\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> In this example, we have 8 seconds. The following operations can be performed to mark all indices:\nSecond 1: Mark index 1, since nums[1] is equal to 0.\nSecond 2: Mark index 2, since nums[2] is equal to 0.\nSecond 3: Decrement index 4 by one. nums becomes [0,0,1,1].\nSecond 4: Decrement index 4 by one. nums becomes [0,0,1,0].\nSecond 5: Decrement index 3 by one. nums becomes [0,0,0,0].\nSecond 6: Mark index 3, since nums[3] is equal to 0.\nSecond 7: Mark index 4, since nums[4] is equal to 0.\nNow all indices have been marked.\nIt can be shown that it is not possible to mark all indices earlier than the 7th second.\nHence, the answer is 7.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,3], changeIndices = [1,2,3]\n<strong>Output:</strong> -1\n<strong>Explanation: </strong>In this example, it can be shown that it is impossible to mark all indices, as we don&#39;t have enough seconds. \nHence, the answer is -1.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= n == nums.length &lt;= 5000</code></li>\n\t<li><code>0 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= m == changeIndices.length &lt;= 5000</code></li>\n\t<li><code>1 &lt;= changeIndices[i] &lt;= n</code></li>\n</ul>\n",
"translatedTitle": "标记所有下标的最早秒数 II",
"translatedContent": "<p>给你两个下标从 <strong>1</strong>&nbsp;开始的整数数组&nbsp;<code>nums</code> 和&nbsp;<code>changeIndices</code>&nbsp;,数组的长度分别为&nbsp;<code>n</code> 和&nbsp;<code>m</code>&nbsp;。</p>\n\n<p>一开始,<code>nums</code>&nbsp;中所有下标都是未标记的,你的任务是标记 <code>nums</code>&nbsp;中 <strong>所有</strong>&nbsp;下标。</p>\n\n<p>从第 <code>1</code>&nbsp;秒到第 <code>m</code>&nbsp;秒(<b>包括&nbsp;</b>第&nbsp;<code>m</code>&nbsp;秒),对于每一秒 <code>s</code>&nbsp;,你可以执行以下操作 <strong>之一</strong>&nbsp;</p>\n\n<ul>\n\t<li>选择范围&nbsp;<code>[1, n]</code>&nbsp;中的一个下标 <code>i</code>&nbsp;,并且将&nbsp;<code>nums[i]</code> <strong>减少</strong>&nbsp;<code>1</code>&nbsp;。</li>\n\t<li>将&nbsp;<code>nums[changeIndices[s]]</code>&nbsp;设置成任意的 <strong>非负</strong>&nbsp;整数。</li>\n\t<li>选择范围&nbsp;<code>[1, n]</code>&nbsp;中的一个下标&nbsp;<code>i</code>&nbsp; 满足&nbsp;<code>nums[i]</code> <strong>等于</strong> <code>0</code>, 并 <strong>标记</strong>&nbsp;下标&nbsp;<code>i</code> 。</li>\n\t<li>什么也不做。</li>\n</ul>\n\n<p>请你返回范围 <code>[1, m]</code>&nbsp;中的一个整数,表示最优操作下,标记&nbsp;<code>nums</code>&nbsp;中 <strong>所有</strong>&nbsp;下标的 <strong>最早秒数</strong>&nbsp;,如果无法标记所有下标,返回 <code>-1</code>&nbsp;。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<b>输入:</b>nums = [3,2,3], changeIndices = [1,3,2,2,2,2,3]\n<b>输出:</b>6\n<b>解释:</b>这个例子中,我们总共有 7 秒。按照以下操作标记所有下标:\n第 1 秒:将 nums[changeIndices[1]] 变为 0 。nums 变为 [0,2,3] 。\n第 2 秒:将 nums[changeIndices[2]] 变为 0 。nums 变为 [0,2,0] 。\n第 3 秒:将 nums[changeIndices[3]] 变为 0 。nums 变为 [0,0,0] 。\n第 4 秒:标记下标 1 ,因为 nums[1] 等于 0 。\n第 5 秒:标记下标 2 ,因为 nums[2] 等于 0 。\n第 6 秒:标记下标 3 ,因为 nums[3] 等于 0 。\n现在所有下标已被标记。\n最早可以在第 6 秒标记所有下标。\n所以答案是 6 。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<b>输入:</b>nums = [0,0,1,2], changeIndices = [1,2,1,2,1,2,1,2]\n<b>输出:</b>7\n<b>解释:</b>这个例子中,我们总共有 8 秒。按照以下操作标记所有下标:\n第 1 秒:标记下标 1 ,因为 nums[1] 等于 0 。\n第 2 秒:标记下标 2 ,因为 nums[2] 等于 0 。\n第 3 秒:将 nums[4] 减少 1 。nums 变为 [0,0,1,1] 。\n第 4 秒:将 nums[4] 减少 1 。nums 变为 [0,0,1,0] 。\n第 5 秒:将 nums[3] 减少 1 。nums 变为 [0,0,0,0] 。\n第 6 秒:标记下标 3 ,因为 nums[3] 等于 0 。\n第 7 秒:标记下标 4 ,因为 nums[4] 等于 0 。\n现在所有下标已被标记。\n最早可以在第 7 秒标记所有下标。\n所以答案是 7 。\n</pre>\n\n<p><strong class=\"example\">示例 3</strong></p>\n\n<pre>\n<b>输入:</b>nums = [1,2,3], changeIndices = [1,2,3]\n<b>输出:</b>-1\n<strong>解释:</strong>这个例子中,无法标记所有下标,因为我们没有足够的秒数。\n所以答案是 -1 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= n == nums.length &lt;= 5000</code></li>\n\t<li><code>0 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= m == changeIndices.length &lt;= 5000</code></li>\n\t<li><code>1 &lt;= changeIndices[i] &lt;= n</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"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}",
"topicTags": [
{
"name": "Greedy",
"slug": "greedy",
"translatedName": "贪心",
"__typename": "TopicTagNode"
},
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "Binary Search",
"slug": "binary-search",
"translatedName": "二分查找",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "C++",
"langSlug": "cpp",
"code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n \n }\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "Java",
"langSlug": "java",
"code": "class Solution {\n public int earliestSecondToMarkIndices(int[] nums, int[] changeIndices) {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python",
"langSlug": "python",
"code": "class Solution(object):\n def earliestSecondToMarkIndices(self, nums, changeIndices):\n \"\"\"\n :type nums: List[int]\n :type changeIndices: List[int]\n :rtype: int\n \"\"\"",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python3",
"langSlug": "python3",
"code": "class Solution:\n def earliestSecondToMarkIndices(self, nums: List[int], changeIndices: List[int]) -> int:",
"__typename": "CodeSnippetNode"
},
{
"lang": "C",
"langSlug": "c",
"code": "int earliestSecondToMarkIndices(int* nums, int numsSize, int* changeIndices, int changeIndicesSize) {\n \n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "C#",
"langSlug": "csharp",
"code": "public class Solution {\n public int EarliestSecondToMarkIndices(int[] nums, int[] changeIndices) {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "JavaScript",
"langSlug": "javascript",
"code": "/**\n * @param {number[]} nums\n * @param {number[]} changeIndices\n * @return {number}\n */\nvar earliestSecondToMarkIndices = function(nums, changeIndices) {\n\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "TypeScript",
"langSlug": "typescript",
"code": "function earliestSecondToMarkIndices(nums: number[], changeIndices: number[]): number {\n \n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "PHP",
"langSlug": "php",
"code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $changeIndices\n * @return Integer\n */\n function earliestSecondToMarkIndices($nums, $changeIndices) {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Swift",
"langSlug": "swift",
"code": "class Solution {\n func earliestSecondToMarkIndices(_ nums: [Int], _ changeIndices: [Int]) -> Int {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Kotlin",
"langSlug": "kotlin",
"code": "class Solution {\n fun earliestSecondToMarkIndices(nums: IntArray, changeIndices: IntArray): Int {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Dart",
"langSlug": "dart",
"code": "class Solution {\n int earliestSecondToMarkIndices(List<int> nums, List<int> changeIndices) {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Go",
"langSlug": "golang",
"code": "func earliestSecondToMarkIndices(nums []int, changeIndices []int) int {\n\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Ruby",
"langSlug": "ruby",
"code": "# @param {Integer[]} nums\n# @param {Integer[]} change_indices\n# @return {Integer}\ndef earliest_second_to_mark_indices(nums, change_indices)\n \nend",
"__typename": "CodeSnippetNode"
},
{
"lang": "Scala",
"langSlug": "scala",
"code": "object Solution {\n def earliestSecondToMarkIndices(nums: Array[Int], changeIndices: Array[Int]): Int = {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Rust",
"langSlug": "rust",
"code": "impl Solution {\n pub fn earliest_second_to_mark_indices(nums: Vec<i32>, change_indices: Vec<i32>) -> i32 {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Racket",
"langSlug": "racket",
"code": "(define/contract (earliest-second-to-mark-indices nums changeIndices)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n )",
"__typename": "CodeSnippetNode"
},
{
"lang": "Erlang",
"langSlug": "erlang",
"code": "-spec earliest_second_to_mark_indices(Nums :: [integer()], ChangeIndices :: [integer()]) -> integer().\nearliest_second_to_mark_indices(Nums, ChangeIndices) ->\n .",
"__typename": "CodeSnippetNode"
},
{
"lang": "Elixir",
"langSlug": "elixir",
"code": "defmodule Solution do\n @spec earliest_second_to_mark_indices(nums :: [integer], change_indices :: [integer]) :: integer\n def earliest_second_to_mark_indices(nums, change_indices) do\n \n end\nend",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"834\", \"totalSubmission\": \"3K\", \"totalAcceptedRaw\": 834, \"totalSubmissionRaw\": 2959, \"acRate\": \"28.2%\"}",
"hints": [
"We need at least <code>n</code> seconds, and at most <code>sum(nums[i]) + n</code> seconds.",
"We can binary search the earliest second where all indices can be marked.",
"If there is an operation where we change <code>nums[changeIndices[i]]</code> to a non-negative value, it is best for it to satisfy the following constraints:<ul>\r\n<li><code>nums[changeIndices[i]]</code> should not be equal to <code>0</code>.</li>\r\n<li><code>nums[changeIndices[i]]</code> should be changed to <code>0</code>.</li>\r\n<li>It should be the first position where <code>changeIndices[i]</code> occurs in <code>changeIndices</code>.</li>\r\n<li>There should be another second, <code>j</code>, where <code>changeIndices[i]</code> will be marked. <code>j</code> is in the range <code>[i + 1, m]</code>.</li>\r\n</ul>",
"Let <code>time_needed = sum(nums[i]) + n</code>. To check if we can mark all indices at some second <code>x</code>, we need to make <code>time_needed <= x</code>, using non-negative change operations as described previously.",
"Using a non-negative change operation on some <code>nums[changeIndices[i]]</code> that satisfies the constraints described previously reduces <code>time_needed</code> by <code>nums[changeIndices[i]] - 1</code>. So, we need to maximize the sum of <code>(nums[changeIndices[i]] - 1)</code> while ensuring that the non-negative change operations still satisfy the constraints.",
"Maximizing the sum of <code>(nums[changeIndices[i]] - 1)</code> can be done greedily using a min-priority queue and going in reverse starting from second <code>x</code> to second <code>1</code>, maximizing the sum of the values in the priority queue and ensuring that for every non-negative change operation on <code>nums[changeIndices[i]]</code> chosen, there is another second <code>j</code> in the range <code>[i + 1, x]</code> where <code>changeIndices[i]</code> can be marked.",
"The answer is the first value of <code>x</code> in the range <code>[1, m]</code> where it is possible to make <code>time_needed <= x</code>, or <code>-1</code> if there is no such second."
],
"solution": null,
"status": null,
"sampleTestCase": "[3,2,3]\n[1,3,2,2,2,2,3]",
"metaData": "{\n \"name\": \"earliestSecondToMarkIndices\",\n \"params\": [\n {\n \"name\": \"nums\",\n \"type\": \"integer[]\"\n },\n {\n \"type\": \"integer[]\",\n \"name\": \"changeIndices\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n }\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [],
"enableRunCode": true,
"envInfo": "{\"cpp\":[\"C++\",\"<p>\\u7248\\u672c\\uff1a<code>clang 17<\\/code> \\u91c7\\u7528\\u6700\\u65b0C++ 20\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O2<\\/code>\\u7ea7\\u4f18\\u5316\\u3002<a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a> \\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\"],\"java\":[\"Java\",\"<p>\\u7248\\u672c\\uff1a<code>OpenJDK 21<\\/code>\\u3002\\u4f7f\\u7528\\u7f16\\u8bd1\\u53c2\\u6570 <code>--enable-preview --release 21<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u88ab\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5305\\u542b Pair \\u7c7b: https:\\/\\/docs.oracle.com\\/javase\\/8\\/javafx\\/api\\/javafx\\/util\\/Pair.html <\\/p>\"],\"python\":[\"Python\",\"<p>\\u7248\\u672c\\uff1a <code>Python 2.7.12<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982\\uff1a<a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u6ce8\\u610f Python 2.7 <a href=\\\"https:\\/\\/www.python.org\\/dev\\/peps\\/pep-0373\\/\\\" target=\\\"_blank\\\">\\u5c06\\u57282020\\u5e74\\u540e\\u4e0d\\u518d\\u7ef4\\u62a4<\\/a>\\u3002 \\u5982\\u60f3\\u4f7f\\u7528\\u6700\\u65b0\\u7248\\u7684Python\\uff0c\\u8bf7\\u9009\\u62e9Python 3\\u3002<\\/p>\"],\"c\":[\"C\",\"<p>\\u7248\\u672c\\uff1a<code>GCC 11<\\/code>\\uff0c\\u91c7\\u7528GNU11\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O2<\\/code>\\u7ea7\\u4f18\\u5316\\u3002 <a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a>\\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u60f3\\u4f7f\\u7528\\u54c8\\u5e0c\\u8868\\u8fd0\\u7b97, \\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 <a href=\\\"https:\\/\\/troydhanson.github.io\\/uthash\\/\\\" target=\\\"_blank\\\">uthash<\\/a>\\u3002 \\\"uthash.h\\\"\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5bfc\\u5165\\u3002\\u8bf7\\u770b\\u5982\\u4e0b\\u793a\\u4f8b:<\\/p>\\r\\n\\r\\n<p><b>1. \\u5f80\\u54c8\\u5e0c\\u8868\\u4e2d\\u6dfb\\u52a0\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; \\/* we'll use this field as the key *\\/\\r\\n char name[10];\\r\\n UT_hash_handle hh; \\/* makes this structure hashable *\\/\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n<p><b>2. \\u5728\\u54c8\\u5e0c\\u8868\\u4e2d\\u67e5\\u627e\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n<p><b>3. \\u4ece\\u54c8\\u5e0c\\u8868\\u4e2d\\u5220\\u9664\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\"],\"csharp\":[\"C#\",\"<p><a href=\\\"https:\\/\\/learn.microsoft.com\\/en-us\\/dotnet\\/csharp\\/whats-new\\/csharp-12\\\" target=\\\"_blank\\\">C# 12<\\/a> \\u8fd0\\u884c\\u5728 .NET 8 \\u4e0a<\\/p>\"],\"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> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/v4.2.3\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.3<\\/a>\\u3002<\\/p>\"],\"ruby\":[\"Ruby\",\"<p>\\u4f7f\\u7528<code>Ruby 3.2<\\/code>\\u6267\\u884c<\\/p>\\r\\n\\r\\n<p>\\u4e00\\u4e9b\\u5e38\\u7528\\u7684\\u6570\\u636e\\u7ed3\\u6784\\u5df2\\u5728 Algorithms \\u6a21\\u5757\\u4e2d\\u63d0\\u4f9b\\uff1ahttps:\\/\\/www.rubydoc.info\\/github\\/kanwei\\/algorithms\\/Algorithms<\\/p>\"],\"swift\":[\"Swift\",\"<p>\\u7248\\u672c\\uff1a<code>Swift 5.9<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/apple\\/swift-algorithms\\/tree\\/1.2.0\\\" target=\\\"_blank\\\">swift-algorithms 1.2.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/apple\\/swift-collections\\/tree\\/1.0.6\\\" target=\\\"_blank\\\">swift-collections 1.0.6<\\/a><\\/p>\\r\\n\\r\\n<p>\\u6211\\u4eec\\u901a\\u5e38\\u4fdd\\u8bc1\\u66f4\\u65b0\\u5230 <a href=\\\"https:\\/\\/swift.org\\/download\\/\\\" target=\\\"_blank\\\">Apple\\u653e\\u51fa\\u7684\\u6700\\u65b0\\u7248Swift<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u53d1\\u73b0Swift\\u4e0d\\u662f\\u6700\\u65b0\\u7248\\u7684\\uff0c\\u8bf7\\u8054\\u7cfb\\u6211\\u4eec\\uff01\\u6211\\u4eec\\u5c06\\u5c3d\\u5feb\\u66f4\\u65b0\\u3002<\\/p>\"],\"golang\":[\"Go\",\"<p>\\u7248\\u672c\\uff1a<code>Go 1.21<\\/code><\\/p>\\r\\n\\r\\n<p>\\u652f\\u6301 <a href=\\\"https:\\/\\/github.com\\/emirpasic\\/gods\\/tree\\/v1.18.1\\\" target=\\\"_blank\\\">https:\\/\\/godoc.org\\/github.com\\/emirpasic\\/gods@v1.18.1<\\/a> \\u7b2c\\u4e09\\u65b9\\u5e93\\u3002<\\/p>\"],\"python3\":[\"Python3\",\"<p>\\u7248\\u672c\\uff1a<code>Python 3.11<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982<a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002 \\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u9700\\u4f7f\\u7528 Map\\/TreeMap \\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"http:\\/\\/www.grantjenks.com\\/docs\\/sortedcontainers\\/\\\" target=\\\"_blank\\\">sortedcontainers<\\/a> \\u5e93\\u3002<\\/p>\"],\"scala\":[\"Scala\",\"<p>\\u7248\\u672c\\uff1a<code>Scala 3.3.1<\\/code><\\/p>\"],\"kotlin\":[\"Kotlin\",\"<p>\\u7248\\u672c\\uff1a<code>Kotlin 1.9.0<\\/code><\\/p>\\r\\n\\r\\n<p>\\u6211\\u4eec\\u4f7f\\u7528\\u7684\\u662f JetBrains \\u63d0\\u4f9b\\u7684 experimental compiler\\u3002\\u5982\\u679c\\u60a8\\u8ba4\\u4e3a\\u60a8\\u9047\\u5230\\u4e86\\u7f16\\u8bd1\\u5668\\u76f8\\u5173\\u7684\\u95ee\\u9898\\uff0c\\u8bf7\\u5411\\u6211\\u4eec\\u53cd\\u9988<\\/p>\"],\"rust\":[\"Rust\",\"<p>\\u7248\\u672c\\uff1a<code>rust 1.74.1<\\/code><\\/p>\\r\\n\\r\\n<p>\\u652f\\u6301 crates.io \\u7684 <a href=\\\"https:\\/\\/crates.io\\/crates\\/rand\\\" target=\\\"_blank\\\">rand<\\/a><\\/p>\"],\"php\":[\"PHP\",\"<p><code>PHP 8.2<\\/code>.<\\/p>\\r\\n\\r\\n<p>With bcmath module.<\\/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> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/v4.2.3\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.3<\\/a>\\u3002<\\/p>\"],\"racket\":[\"Racket\",\"<p><a href=\\\"https:\\/\\/docs.racket-lang.org\\/guide\\/performance.html#%28tech._c%29\\\" target=\\\"_blank\\\">Racket CS<\\/a> v8.11<\\/p>\\r\\n\\r\\n<p>\\u4f7f\\u7528 #lang racket<\\/p>\\r\\n\\r\\n<p>\\u5df2\\u9884\\u5148 (require data\\/gvector data\\/queue data\\/order data\\/heap). \\u82e5\\u9700\\u4f7f\\u7528\\u5176\\u5b83\\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u53ef\\u81ea\\u884c require\\u3002<\\/p>\"],\"erlang\":[\"Erlang\",\"Erlang\\/OTP 26\"],\"elixir\":[\"Elixir\",\"Elixir 1.15 with Erlang\\/OTP 26\"],\"dart\":[\"Dart\",\"<p>Dart 3.2<\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5c06\\u4f1a\\u88ab\\u4e0d\\u7f16\\u8bd1\\u76f4\\u63a5\\u8fd0\\u884c<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "[3,2,3]\n[1,3,2,2,2,2,3]\n[0,0,1,2]\n[1,2,1,2,1,2,1,2]\n[1,2,3]\n[1,2,3]",
"__typename": "QuestionNode"
}
}
}