mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-25 17:50:26 +08:00
179 lines
27 KiB
JSON
179 lines
27 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "3292",
|
||
"questionFrontendId": "3048",
|
||
"categoryTitle": "Algorithms",
|
||
"boundTopicId": 2650518,
|
||
"title": "Earliest Second to Mark Indices I",
|
||
"titleSlug": "earliest-second-to-mark-indices-i",
|
||
"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>If <code>nums[changeIndices[s]]</code> is <strong>equal</strong> to <code>0</code>, <strong>mark</strong> the index <code>changeIndices[s]</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> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1]\n<strong>Output:</strong> 8\n<strong>Explanation:</strong> In this example, we have 8 seconds. The following operations can be performed to mark all indices:\nSecond 1: Choose index 1 and decrement nums[1] by one. nums becomes [1,2,0].\nSecond 2: Choose index 1 and decrement nums[1] by one. nums becomes [0,2,0].\nSecond 3: Choose index 2 and decrement nums[2] by one. nums becomes [0,1,0].\nSecond 4: Choose index 2 and decrement nums[2] by one. nums becomes [0,0,0].\nSecond 5: Mark the index changeIndices[5], which is marking index 3, since nums[3] is equal to 0.\nSecond 6: Mark the index changeIndices[6], which is marking index 2, since nums[2] is equal to 0.\nSecond 7: Do nothing.\nSecond 8: Mark the index changeIndices[8], which is marking index 1, since nums[1] 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 8th second.\nHence, the answer is 8.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,3], changeIndices = [1,1,1,2,1,1,1]\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: Choose index 2 and decrement nums[2] by one. nums becomes [1,2].\nSecond 2: Choose index 2 and decrement nums[2] by one. nums becomes [1,1].\nSecond 3: Choose index 2 and decrement nums[2] by one. nums becomes [1,0].\nSecond 4: Mark the index changeIndices[4], which is marking index 2, since nums[2] is equal to 0.\nSecond 5: Choose index 1 and decrement nums[1] by one. nums becomes [0,0].\nSecond 6: Mark the index changeIndices[6], which is marking index 1, since nums[1] 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 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1], changeIndices = [2,2,2]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> In this example, it is impossible to mark all indices because index 1 isn't in changeIndices.\nHence, the answer is -1.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= n == nums.length <= 2000</code></li>\n\t<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>\n\t<li><code>1 <= m == changeIndices.length <= 2000</code></li>\n\t<li><code>1 <= changeIndices[i] <= n</code></li>\n</ul>\n",
|
||
"translatedTitle": "标记所有下标的最早秒数 I",
|
||
"translatedContent": "<p>给你两个下标从 <strong>1</strong> 开始的整数数组 <code>nums</code> 和 <code>changeIndices</code> ,数组的长度分别为 <code>n</code> 和 <code>m</code> 。</p>\n\n<p>一开始,<code>nums</code> 中所有下标都是未标记的,你的任务是标记 <code>nums</code> 中 <strong>所有</strong> 下标。</p>\n\n<p>从第 <code>1</code> 秒到第 <code>m</code> 秒(<b>包括 </b>第 <code>m</code> 秒),对于每一秒 <code>s</code> ,你可以执行以下操作 <strong>之一</strong> :</p>\n\n<ul>\n\t<li>选择范围 <code>[1, n]</code> 中的一个下标 <code>i</code> ,并且将 <code>nums[i]</code> <strong>减少</strong> <code>1</code> 。</li>\n\t<li>如果 <code>nums[changeIndices[s]]</code> <strong>等于</strong> <code>0</code> ,<strong>标记</strong> 下标 <code>changeIndices[s]</code> 。</li>\n\t<li>什么也不做。</li>\n</ul>\n\n<p>请你返回范围 <code>[1, m]</code> 中的一个整数,表示最优操作下,标记 <code>nums</code> 中 <strong>所有</strong> 下标的 <strong>最早秒数</strong> ,如果无法标记所有下标,返回 <code>-1</code> 。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1]\n<b>输出:</b>8\n<b>解释:</b>这个例子中,我们总共有 8 秒。按照以下操作标记所有下标:\n第 1 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [1,2,0] 。\n第 2 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [0,2,0] 。\n第 3 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [0,1,0] 。\n第 4 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [0,0,0] 。\n第 5 秒,标记 changeIndices[5] ,也就是标记下标 3 ,因为 nums[3] 等于 0 。\n第 6 秒,标记 changeIndices[6] ,也就是标记下标 2 ,因为 nums[2] 等于 0 。\n第 7 秒,什么也不做。\n第 8 秒,标记 changeIndices[8] ,也就是标记下标 1 ,因为 nums[1] 等于 0 。\n现在所有下标已被标记。\n最早可以在第 8 秒标记所有下标。\n所以答案是 8 。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [1,3], changeIndices = [1,1,1,2,1,1,1]\n<b>输出:</b>6\n<b>解释:</b>这个例子中,我们总共有 7 秒。按照以下操作标记所有下标:\n第 1 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,2] 。\n第 2 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,1] 。\n第 3 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,0] 。\n第 4 秒:标记 changeIndices[4] ,也就是标记下标 2 ,因为 nums[2] 等于 0 。\n第 5 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [0,0] 。\n第 6 秒:标记 changeIndices[6] ,也就是标记下标 1 ,因为 nums[1] 等于 0 。\n现在所有下标已被标记。\n最早可以在第 6 秒标记所有下标。\n所以答案是 6 。\n</pre>\n\n<p><strong class=\"example\">示例 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1], changeIndices = [2,2,2]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> 这个例子中,无法标记所有下标,因为下标 1 不在 changeIndices 中。\n所以答案是 -1 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= n == nums.length <= 2000</code></li>\n\t<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>\n\t<li><code>1 <= m == changeIndices.length <= 2000</code></li>\n\t<li><code>1 <= changeIndices[i] <= n</code></li>\n</ul>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Medium",
|
||
"likes": 17,
|
||
"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": "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\": \"2K\", \"totalSubmission\": \"4.3K\", \"totalAcceptedRaw\": 1964, \"totalSubmissionRaw\": 4282, \"acRate\": \"45.9%\"}",
|
||
"hints": [
|
||
"Consider using binary search.",
|
||
"Suppose the <code>answer <= x</code>; we can mark each index as late as possible. Namely, mark each index at the last occurrence in the array <code>changeIndices[1..x]</code>.",
|
||
"When marking an index, which is the last occurrence at the second <code>i</code>, we check whether we have a sufficient number of decrement operations to mark all the previous indices whose last occurrences have already been marked, and the current index, i.e., <code>i - sum_of_marked_indices_values - cnt_of_marked_indices >= nums[changeIndices[i]]</code>.",
|
||
"The answer is the earliest second when all indices can be marked after running the binary search or <code>-1</code> if there is no such second."
|
||
],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "[2,2,0]\n[2,2,2,2,3,2,2,1]",
|
||
"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": "[2,2,0]\n[2,2,2,2,3,2,2,1]\n[1,3]\n[1,1,1,2,1,1,1]\n[0,1]\n[2,2,2]",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |