{"id":399,"date":"2020-09-26T10:37:05","date_gmt":"2020-09-26T02:37:05","guid":{"rendered":"http:\/\/39.96.58.60\/?p=399"},"modified":"2022-10-18T16:39:35","modified_gmt":"2022-10-18T08:39:35","slug":"leetcode-237-%e5%88%a0%e9%99%a4%e9%93%be%e8%a1%a8%e4%b8%ad%e7%9a%84%e8%8a%82%e7%82%b9","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=399","title":{"rendered":"Leetcode 237. \u5220\u9664\u94fe\u8868\u4e2d\u7684\u8282\u70b9"},"content":{"rendered":"<p>\u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5176\u53ef\u4ee5\u5220\u9664\u67d0\u4e2a\u94fe\u8868\u4e2d\u7ed9\u5b9a\u7684\uff08\u975e\u672b\u5c3e\uff09\u8282\u70b9\u3002\u4f20\u5165\u51fd\u6570\u7684\u552f\u4e00\u53c2\u6570\u4e3a <strong>\u8981\u88ab\u5220\u9664\u7684\u8282\u70b9<\/strong> \u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u73b0\u6709\u4e00\u4e2a\u94fe\u8868 &#8212;&nbsp;head =&nbsp;[4,5,1,9]\uff0c\u5b83\u53ef\u4ee5\u8868\u793a\u4e3a:<\/p>\n<p><img alt=\"\" src=\"https:\/\/assets.leetcode-cn.com\/aliyun-lc-upload\/uploads\/2019\/01\/19\/237_example.png\" style=\"height: 49px; width: 300px;\"><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>head = [4,5,1,9], node = 5\n\n<strong>\u8f93\u51fa\uff1a<\/strong>[4,1,9]\n\n<strong>\u89e3\u91ca\uff1a<\/strong>\u7ed9\u5b9a\u4f60\u94fe\u8868\u4e2d\u503c\u4e3a&nbsp;5&nbsp;\u7684\u7b2c\u4e8c\u4e2a\u8282\u70b9\uff0c\u90a3\u4e48\u5728\u8c03\u7528\u4e86\u4f60\u7684\u51fd\u6570\u4e4b\u540e\uff0c\u8be5\u94fe\u8868\u5e94\u53d8\u4e3a 4 -&gt; 1 -&gt; 9.\n\n<\/pre>\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>head = [4,5,1,9], node = 1\n\n<strong>\u8f93\u51fa\uff1a<\/strong>[4,5,9]\n\n<strong>\u89e3\u91ca\uff1a<\/strong>\u7ed9\u5b9a\u4f60\u94fe\u8868\u4e2d\u503c\u4e3a&nbsp;1&nbsp;\u7684\u7b2c\u4e09\u4e2a\u8282\u70b9\uff0c\u90a3\u4e48\u5728\u8c03\u7528\u4e86\u4f60\u7684\u51fd\u6570\u4e4b\u540e\uff0c\u8be5\u94fe\u8868\u5e94\u53d8\u4e3a 4 -&gt; 5 -&gt; 9.\n\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u94fe\u8868\u81f3\u5c11\u5305\u542b\u4e24\u4e2a\u8282\u70b9\u3002<\/li>\n<li>\u94fe\u8868\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\u3002<\/li>\n<li>\u7ed9\u5b9a\u7684\u8282\u70b9\u4e3a\u975e\u672b\u5c3e\u8282\u70b9\u5e76\u4e14\u4e00\u5b9a\u662f\u94fe\u8868\u4e2d\u7684\u4e00\u4e2a\u6709\u6548\u8282\u70b9\u3002<\/li>\n<li>\u4e0d\u8981\u4ece\u4f60\u7684\u51fd\u6570\u4e2d\u8fd4\u56de\u4efb\u4f55\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>**\u96be\u5ea6**: Easy<\/p>\n<p>**\u6807\u7b7e**: \u94fe\u8868\u3001<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code>\n# -*- coding: utf-8 -*-\n# @Author  : LG\n\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, x):\n#         self.val = x\n#         self.next = None\n\n\"\"\"\n\u6267\u884c\u7528\u65f6\uff1a44 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8693.79% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.8 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8694.12% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u8fd9\u4e2a\u9898\u60f3\u534a\u5929\u6ca1\u60f3\u51fa\u6765\uff0c\u7136\u540e\u770b\u4e86\u522b\u4eba\u89e3\u9898\u624d\u60f3\u660e\u767d\u8fd9\u9898\u8981\u5e72\u5565\n    \u9898\u76ee\u7684\u610f\u601d\u662f\u9700\u8981\u5220\u9664\u8fd9\u4e2a\u8282\u70b9\uff0c\u76f4\u63a5\u628a\u8fd9\u4e2a\u8282\u70b9\u7684\u503c\u4e0enext\u66f4\u65b0\u4e3a\u4e0b\u4e00\u4e2a\u5373\u53ef\n\n\"\"\"\nclass Solution:\n    def deleteNode(self, node):\n        \"\"\"\n        :type node: ListNode\n        :rtype: void Do not return anything, modify node in-place instead.\n        \"\"\"\n        node.val = node.next.val\n        node.next = node.next.next<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5176\u53ef\u4ee5\u5220\u9664\u67d0\u4e2a\u94fe\u8868\u4e2d\u7ed9\u5b9a\u7684\uff08\u975e\u672b\u5c3e\uff09\u8282\u70b9\u3002\u4f20\u5165\u51fd\u6570\u7684\u552f\u4e00\u53c2\u6570\u4e3a \u8981\u88ab\u5220\u9664\u7684\u8282\u70b9 \u3002 &#038;nbs&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/399"}],"collection":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=399"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/399\/revisions"}],"predecessor-version":[{"id":400,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/399\/revisions\/400"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=399"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}