{"id":6615,"date":"2021-09-18T15:03:42","date_gmt":"2021-09-18T15:03:42","guid":{"rendered":"https:\/\/blog.gwlin.com\/?p=6615"},"modified":"2023-04-01T23:29:00","modified_gmt":"2023-04-01T15:29:00","slug":"leetcode-%e7%b3%bb%e5%88%97-83-remove-duplicates-from-sorted-list-%e7%a7%bb%e9%99%a4%e6%9c%89%e5%ba%8f%e9%93%be%e8%a1%a8%e9%87%8d%e5%a4%8d%e5%85%83%e7%b4%a0-%e7%9a%84php%e8%a7%a3%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.gwlin.com\/blog\/posts\/6615","title":{"rendered":"[Leetcode \u7cfb\u5217] 83. Remove Duplicates from Sorted List \u79fb\u9664\u6709\u5e8f\u94fe\u8868\u91cd\u590d\u5143\u7d20 \u7684php\u89e3\u6cd5"},"content":{"rendered":"\n<p>\u94fe\u8868\u5bf9\u4e8ephp\u5f00\u53d1\u6765\u8bf4\u53ef\u80fd\u63a5\u89e6\u7684\u6bd4\u8f83\u5c11\uff0c\u4f46\u5176\u5b9e\u7406\u89e3\u4e86\u4e4b\u540e\u8fd8\u662f\u633a\u7b80\u5355\u7684\u3002\u611f\u89c9\u8ddf\u5904\u7406\u6570\u7ec4\u5dee\u4e0d\u591a\u3002\u6027\u80fd\u7684\u8bdd\u5c31\u5148\u4e0d\u8003\u8651\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/**\r\n * Definition for a singly-linked list.\r\n * class ListNode {\r\n *     public $val = 0;\r\n *     public $next = null;\r\n *     function __construct($val = 0, $next = null) {\r\n *         $this-&gt;val = $val;\r\n *         $this-&gt;next = $next;\r\n *     }\r\n * }\r\n *\/\r\nclass Solution {\r\n\r\n    \/**\r\n     * @param ListNode $head\r\n     * @return ListNode\r\n     *\/\r\n    function deleteDuplicates($head) {\r\n        $current=$head;\r\n        while (true){\r\n            $next=$current-&gt;next;\r\n            if($next===null){ \/\/ \u6ca1\u6709\u4e0b\u4e00\u4e2anode\u5c31\u8df3\u51fa\r\n                break;\r\n            }\r\n            if($current-&gt;val===$next-&gt;val){ \/\/ \u5982\u679c\u76f8\u540c\uff0c\u628a\u5f53\u524dnode\u7684next\u6307\u5411\u4e0b\u4e0b\u4e2a\u5143\u7d20\r\n                $current-&gt;next=$next-&gt;next;\r\n            }else{ \/\/ \u4e0d\u540c\u7684\u8bdd\uff0c\u628a\u5f53\u524dnode\u6362\u6210next\uff0c\u5373\u7ee7\u7eed\u4e0b\u4e00\u4e2a\u5143\u7d20\r\n                $current=$next;\r\n            }\r\n        }\r\n        return $head;\r\n    }\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u94fe\u8868\u5bf9\u4e8ephp\u5f00\u53d1\u6765\u8bf4\u53ef\u80fd\u63a5\u89e6\u7684\u6bd4\u8f83\u5c11\uff0c\u4f46\u5176\u5b9e\u7406\u89e3\u4e86\u4e4b\u540e\u8fd8\u662f\u633a\u7b80\u5355\u7684\u3002\u611f\u89c9\u8ddf\u5904\u7406\u6570\u7ec4\u5dee\u4e0d\u591a\u3002\u6027\u80fd\u7684\u8bdd\u5c31\u5148\u4e0d\u8003\u8651\u4e86\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[179],"tags":[],"class_list":["post-6615","post","type-post","status-publish","format-standard","hentry","category-notes"],"_links":{"self":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/6615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/comments?post=6615"}],"version-history":[{"count":1,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/6615\/revisions"}],"predecessor-version":[{"id":42914,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/6615\/revisions\/42914"}],"wp:attachment":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/media?parent=6615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/categories?post=6615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/tags?post=6615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}