{"id":2617,"date":"2022-02-04T16:18:47","date_gmt":"2022-02-04T08:18:47","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2617"},"modified":"2022-02-04T16:18:48","modified_gmt":"2022-02-04T08:18:48","slug":"leetcodeday136","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/04\/leetcodeday136\/","title":{"rendered":"leetcodeday136 &#8211;\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a<strong>\u975e\u7a7a<\/strong>\u6574\u6570\u6570\u7ec4\uff0c\u9664\u4e86\u67d0\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\u4ee5\u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002\u627e\u51fa\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n\n\n\n<p>\u4f60\u7684\u7b97\u6cd5\u5e94\u8be5\u5177\u6709\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3002 \u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u989d\u5916\u7a7a\u95f4\u6765\u5b9e\u73b0\u5417\uff1f<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong> &#91;2,2,1]\n<strong>\u8f93\u51fa:<\/strong> 1<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong> &#91;4,1,2,1,2]\n<strong>\u8f93\u51fa:<\/strong> 4<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"959\" height=\"134\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-40.png\" alt=\"\" class=\"wp-image-2618\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-40.png 959w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-40-300x42.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-40-768x107.png 768w\" sizes=\"(max-width: 959px) 100vw, 959px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=136 lang=python3\r\n#\r\n# &#91;136] \u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def singleNumber(self, nums: List&#91;int]) -> int:\r\n        return reduce(lambda x, y: x ^ y, nums)\r\n# @lc code=end<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"864\" height=\"235\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-41.png\" alt=\"\" class=\"wp-image-2620\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-41.png 864w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-41-300x82.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-41-768x209.png 768w\" sizes=\"(max-width: 864px) 100vw, 864px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>reduce()<\/strong>\u00a0\u51fd\u6570\u4f1a\u5bf9\u53c2\u6570\u5e8f\u5217\u4e2d\u5143\u7d20\u8fdb\u884c\u7d2f\u79ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>reduce(function, iterable&#91;, initializer])<\/code><\/pre>\n\n\n\n<p>\u51fd\u6570\u5c06\u4e00\u4e2a\u6570\u636e\u96c6\u5408\uff08\u94fe\u8868\uff0c\u5143\u7ec4\u7b49\uff09\u4e2d\u7684\u6240\u6709\u6570\u636e\u8fdb\u884c\u4e0b\u5217\u64cd\u4f5c\uff1a\u7528\u4f20\u7ed9 reduce \u4e2d\u7684\u51fd\u6570 function\uff08\u6709\u4e24\u4e2a\u53c2\u6570\uff09\u5148\u5bf9\u96c6\u5408\u4e2d\u7684\u7b2c 1\u30012 \u4e2a\u5143\u7d20\u8fdb\u884c\u64cd\u4f5c\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u518d\u4e0e\u7b2c\u4e09\u4e2a\u6570\u636e\u7528 function \u51fd\u6570\u8fd0\u7b97\uff0c\u6700\u540e\u5f97\u5230\u4e00\u4e2a\u7ed3\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>def<\/strong>\u00a0add(x,\u00a0y)\u00a0: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0# \u4e24\u6570\u76f8\u52a0\n    <strong>return<\/strong>\u00a0x + y\nsum1\u00a0=\u00a0reduce(add,\u00a0[1,2,3,4,5])\u00a0\u00a0\u00a0# \u8ba1\u7b97\u5217\u8868\u548c\uff1a1+2+3+4+5\nsum2\u00a0=\u00a0reduce(<strong>lambda<\/strong>\u00a0x,\u00a0y: x+y,\u00a0[1,2,3,4,5])\u00a0\u00a0# \u4f7f\u7528 lambda \u533f\u540d\u51fd\u6570\n<strong>print<\/strong>(sum1)\n<strong>print<\/strong>(sum2)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u6574\u6570\u6570\u7ec4\uff0c\u9664\u4e86\u67d0\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\u4ee5\u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002\u627e\u51fa\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002 \u8bf4\u660e\uff1a &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/04\/leetcodeday136\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday136 &#8211;\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2617"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2617"}],"version-history":[{"count":5,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2617\/revisions"}],"predecessor-version":[{"id":2624,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2617\/revisions\/2624"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2617"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}