{"id":5717,"date":"2021-01-04T11:30:44","date_gmt":"2021-01-04T11:30:44","guid":{"rendered":"https:\/\/blog.gwlin.com\/?p=5717"},"modified":"2023-03-31T08:40:35","modified_gmt":"2023-03-31T08:40:35","slug":"[LeetCode \u7cfb\u5217] Add Two Numbers \u7684php\u89e3\u6cd5","status":"publish","type":"post","link":"https:\/\/www.gwlin.com\/blog\/posts\/5717","title":{"rendered":"[LeetCode \u7cfb\u5217] Add Two Numbers \u7684php\u89e3\u6cd5"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code class=\"prettyprint\"  lang=\"php\" class=\"language-php\">\/**\n * Definition for a singly-linked list.\n * class ListNode {\n *     public $val = 0;\n *     public $next = null;\n *     function __construct($val = 0, $next = null) {\n *         $this-&gt;val = $val;\n *         $this-&gt;next = $next;\n *     }\n * }\n *\/\nclass Solution {\n\n    \/**\n     * @param ListNode $l1\n     * @param ListNode $l2\n     * @return ListNode\n     *\/\n    function addTwoNumbers($l1, $l2) {\n        $result=(is_null($l1)?0:$l1-&gt;val)+(is_null($l2)?0:$l2-&gt;val);\n        if($result&gt;=10){\n            $result-=10;\n            if(is_null($l1-&gt;next)){\n                $l1-&gt;next=new ListNode;\n            }\n            $l1-&gt;next-&gt;val+=1;\n        }\n        $node=new ListNode($result);\n        if(is_null($l1-&gt;next) &amp;&amp; is_null($l2-&gt;next)){\n            return $node;\n        }\n        $node-&gt;next=$this-&gt;addTwoNumbers($l1-&gt;next,$l2-&gt;next);\n        return $node;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Add Two Numbers \u7684php\u89e3\u6cd5<\/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":[198,186],"class_list":["post-5717","post","type-post","status-publish","format-standard","hentry","category-notes","tag-leetcode","tag-php"],"_links":{"self":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/5717","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=5717"}],"version-history":[{"count":0,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/5717\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/media?parent=5717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/categories?post=5717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/tags?post=5717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}