{"id":2327,"date":"2023-10-11T16:53:53","date_gmt":"2023-10-11T08:53:53","guid":{"rendered":"https:\/\/white-night.club\/?p=2327"},"modified":"2023-11-09T11:07:50","modified_gmt":"2023-11-09T03:07:50","slug":"ad39","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/11\/ad39\/","title":{"rendered":"2620.\u00a0\u8ba1\u6570\u5668"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u578b\u53c2\u6570&nbsp;<code>n<\/code>\uff0c\u8bf7\u4f60\u7f16\u5199\u5e76\u8fd4\u56de\u4e00\u4e2a&nbsp;<code>counter<\/code><strong>&nbsp;<\/strong>\u51fd\u6570\u3002\u8fd9\u4e2a&nbsp;<code>counter<\/code><strong>&nbsp;<\/strong>\u51fd\u6570\u6700\u521d\u8fd4\u56de&nbsp;<code>n<\/code>\uff0c\u6bcf\u6b21\u8c03\u7528\u5b83\u65f6\u4f1a\u8fd4\u56de\u524d\u4e00\u4e2a\u503c\u52a0 1 \u7684\u503c (&nbsp;<code>n<\/code>&nbsp;,&nbsp;&nbsp;<code>n + 1<\/code>&nbsp;,&nbsp;&nbsp;<code>n + 2<\/code>&nbsp;\uff0c\u7b49\u7b49)\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>\nn = 10 \n[\"call\",\"call\",\"call\"]\n<strong>\u8f93\u51fa\uff1a<\/strong>[10,11,12]\n<strong>\u89e3\u91ca\uff1a<\/strong>\ncounter() = 10 \/\/ \u7b2c\u4e00\u6b21\u8c03\u7528 counter()\uff0c\u8fd4\u56de n\u3002\ncounter() = 11 \/\/ \u8fd4\u56de\u4e0a\u6b21\u8c03\u7528\u7684\u503c\u52a0 1\u3002\ncounter() = 12 \/\/ \u8fd4\u56de\u4e0a\u6b21\u8c03\u7528\u7684\u503c\u52a0 1\u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>\nn = -2\n[\"call\",\"call\",\"call\",\"call\",\"call\"]\n<strong>\u8f93\u51fa\uff1a<\/strong>[-2,-1,0,1,2]\n<strong>\u89e3\u91ca\uff1a<\/strong>counter() \u6700\u521d\u8fd4\u56de -2\u3002\u7136\u540e\u5728\u6bcf\u4e2a\u540e\u7eed\u8c03\u7528\u540e\u589e\u52a0 1\u3002\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><code>-1000<sup>&nbsp;<\/sup>&lt;= n &lt;= 1000<\/code><\/li>\n\n\n\n<li><code>0 &lt;= calls.length &lt;= 1000<\/code><\/li>\n\n\n\n<li><code>calls[i] === \"call\"<\/code><\/li>\n<\/ul>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u7ec6\u8bf4\u95ed\u5305<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u95ed\u5305\uff0c\u53ef\u4ee5\u5728\u51fd\u6570\u6267\u884c\u65f6\u4ea7\u751f\u4e00\u4e2a\u79c1\u6709\u57df\uff0c\u8fd9\u4e2a\u57df\u5185\u7684\u53d8\u91cf\u4e0d\u4f1a\u5728\u51fd\u6570\u6267\u884c\u5b8c\u7684\u65f6\u5019\u91ca\u653e\u3002\u5177\u4f53\u7684\u7b49\u540e\u9762\u5199JavaScript\u6587\u7ae0\u7684\u65f6\u5019\u518d\u8be6\u7ec6\u4ecb\u7ecd\u66f4\u597d\u4e00\u70b9\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u552f\u4e00\u8981\u6ce8\u610f\u7684\u5730\u65b9\u5927\u6982\u5c31\u662f\u6211\u6807\u8bb0\u7684\u5730\u65b9\u3002\u8fd9\u91cc\u552f\u4e00\u4e0d\u80fd\u5199\u7684\u5c31\u662f&#8221;n+1&#8243;\u3002\u4f60\u5199return n=n+1,return n++,return n+=1\u90fd\u884c\u3002\u5c31\u662f\u4e0d\u80fd\u5199n+1.<\/p>\n\n\n\n<p>\u597d\u5427\uff0c\u5199\u7740\u5199\u7740\u7a81\u7136\u53d1\u73b0\u8fd9\u4e5f\u4e0d\u662f\u4ec0\u4e48\u5f88\u9700\u8981\u8bb0\u5f55\u7684\u95ee\u9898\u3002\u672c\u6765\u6211\u4ee5\u4e3a\u662fJavaScript\u4e2dreturn\u7684\u7279\u6027\u5565\u7684\u3002\u521a\u521a\u7a81\u7136\u60f3\u8d77\u6765return n+1\u4e0d\u4f1a\u4fee\u6539\u539f\u6765\u7684\u503cn\uff0c\u592a\u4e45\u6ca1\u5199\u8fd9\u79cd\u7ed9\u5fd8\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * @param {number} n\n * @return {Function} counter\n *\/\nvar createCounter = function(n) {\n    \n    return function() {\n        <mark style=\"background-color:rgba(0, 0, 0, 0);color:#ffdf00\" class=\"has-inline-color\">return n++;<\/mark>\n    };\n};\n\n\/** \n * const counter = createCounter(10)\n * counter() \/\/ 10\n * counter() \/\/ 11\n * counter() \/\/ 12\n *\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u95ed\u5305<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2327"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=2327"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2327\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=2327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}