mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-21 13:06:47 +08:00
update
This commit is contained in:
@@ -12,12 +12,12 @@
|
||||
"translatedContent": "<p>请你编写一个函数 <code>fn</code>,它接收另一个函数作为输入,并返回该函数的 <strong>记忆化</strong> 后的结果。</p>\n\n<p><strong>记忆函数</strong> 是一个对于相同的输入永远不会被调用两次的函数。相反,它将返回一个缓存值。</p>\n\n<p>你可以假设有 <strong>3</strong> 个可能的输入函数:<code>sum</code> 、<code>fib</code> 和 <code>factorial</code> 。</p>\n\n<ul>\n\t<li> <code>sum</code> 接收两个整型参数 <code>a</code> 和 <code>b</code> ,并返回 <code>a + b</code> 。假设如果参数 <code>(b, a)</code> 已经缓存了值,其中 <code>a != b</code>,它不能用于参数 <code>(a, b)</code>。例如,如果参数是 <code>(3, 2)</code> 和 <code>(2, 3)</code>,则应进行两个单独的调用。</li>\n\t<li> <code>fib</code> 接收一个整型参数 <code>n</code> ,如果 <code>n <= 1</code> 则返回 <code>1</code>,否则返回 <code>fib (n - 1) + fib (n - 2)</code>。</li>\n\t<li> <code>factorial</code> 接收一个整型参数 <code>n</code> ,如果 <code>n <= 1</code> 则返回 <code>1</code> ,否则返回 <code>factorial(n - 1) * n</code> 。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\nfnName = \"sum\"\nactions = [\"call\",\"call\",\"getCallCount\",\"call\",\"getCallCount\"]\nvalues = [[2,2],[2,2],[],[1,2],[]]\n<strong>输出:</strong>[4,4,1,3,2]\n<strong>解释:</strong>\nconst sum = (a, b) => a + b;\nconst memoizedSum = memoize(sum);\nmemoizedSum (2, 2);// \"call\" - 返回 4。sum() 被调用,因为之前没有使用参数 (2, 2) 调用过。\nmemoizedSum (2, 2);// \"call\" - 返回 4。没有调用 sum(),因为前面有相同的输入。\n// \"getCallCount\" - 总调用数: 1\nmemoizedSum(1, 2);// \"call\" - 返回 3。sum() 被调用,因为之前没有使用参数 (1, 2) 调用过。\n// \"getCallCount\" - 总调用数: 2\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:\n</strong>fnName = \"factorial\"\nactions = [\"call\",\"call\",\"call\",\"getCallCount\",\"call\",\"getCallCount\"]\nvalues = [[2],[3],[2],[],[3],[]]\n<strong>输出:</strong>[2,6,2,2,6,2]\n<strong>解释:</strong>\nconst factorial = (n) => (n <= 1) ? 1 : (n * factorial(n - 1));\nconst memoFactorial = memoize(factorial);\nmemoFactorial(2); // \"call\" - 返回 2。\nmemoFactorial(3); // \"call\" - 返回 6。\nmemoFactorial(2); // \"call\" - 返回 2。 没有调用 factorial(),因为前面有相同的输入。\n// \"getCallCount\" - 总调用数:2\nmemoFactorial(3); // \"call\" - 返回 6。 没有调用 factorial(),因为前面有相同的输入。\n// \"getCallCount\" - 总调用数:2\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:\n</strong>fnName = \"fib\"\nactions = [\"call\",\"getCallCount\"]\nvalues = [[5],[]]\n<strong>输出:</strong>[8,1]\n<strong>解释:\n</strong>fib(5) = 8 // \"call\"\n// \"getCallCount\" - 总调用数:1\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>0 <= a, b <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= n <= 10</code></li>\n\t<li><code>1 <= actions.length <= 10<sup>5</sup></code></li>\n\t<li><code>actions.length === values.length</code></li>\n\t<li><code>actions[i]</code> 为 \"call\" 和 \"getCallCount\" 中的一个</li>\n\t<li><code>fnName</code> 为 \"sum\", \"factorial\" 和 \"fib\" 中的一个</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 22,
|
||||
"likes": 24,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Counter\", \"titleSlug\": \"counter\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u8ba1\\u6570\\u5668\", \"isPaidOnly\": false}, {\"title\": \"Curry\", \"titleSlug\": \"curry\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u67ef\\u91cc\\u5316\", \"isPaidOnly\": true}, {\"title\": \"Function Composition\", \"titleSlug\": \"function-composition\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u590d\\u5408\\u51fd\\u6570\", \"isPaidOnly\": false}, {\"title\": \"Memoize II\", \"titleSlug\": \"memoize-ii\", \"difficulty\": \"Hard\", \"translatedTitle\": \"\\u8bb0\\u5fc6\\u51fd\\u6570 II\", \"isPaidOnly\": false}]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": false, \"java\": true, \"python\": true, \"python3\": false, \"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}",
|
||||
"langToValidPlayground": "{\"cpp\": false, \"java\": true, \"python3\": false, \"python\": true, \"javascript\": false, \"typescript\": false, \"csharp\": false, \"c\": false, \"golang\": false, \"kotlin\": false, \"swift\": false, \"rust\": false, \"ruby\": false, \"php\": false, \"dart\": false, \"scala\": false, \"elixir\": false, \"erlang\": false, \"racket\": false, \"cangjie\": false, \"bash\": false, \"html\": false, \"pythonml\": false, \"react\": false, \"vanillajs\": false, \"mysql\": false, \"mssql\": false, \"postgresql\": false, \"oraclesql\": false, \"pythondata\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
@@ -34,7 +34,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"8.8K\", \"totalSubmission\": \"14.2K\", \"totalAcceptedRaw\": 8753, \"totalSubmissionRaw\": 14232, \"acRate\": \"61.5%\"}",
|
||||
"stats": "{\"totalAccepted\": \"10.5K\", \"totalSubmission\": \"16.8K\", \"totalAcceptedRaw\": 10459, \"totalSubmissionRaw\": 16757, \"acRate\": \"62.4%\"}",
|
||||
"hints": [
|
||||
"You can create copy of a function by spreading function parameters. \r\n\r\nfunction outerFunction(passedFunction) {\r\n return newFunction(...params) {\r\n return passedFunction(...params);\r\n };\r\n}",
|
||||
"params is an array. Since you know all values in the array are numbers, you can turn it into a string with JSON.stringify().",
|
||||
@@ -48,7 +48,7 @@
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"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>\"]}",
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 22.14.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> \\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/datastructures-js.info\\/docs\\\" target=\\\"_blank\\\"> datastructures-js <\\/a>\\u5e93\\u6240\\u63d0\\u4f9b\\u7684\\u6570\\u636e\\u7ed3\\u6784\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.7.3<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2024<\\/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> \\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/datastructures-js.info\\/docs\\\" target=\\\"_blank\\\"> datastructures-js <\\/a>\\u5e93\\u6240\\u63d0\\u4f9b\\u7684\\u6570\\u636e\\u7ed3\\u6784\\u3002<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
|
Reference in New Issue
Block a user