{"id":2535,"date":"2022-02-02T16:37:20","date_gmt":"2022-02-02T08:37:20","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2535"},"modified":"2022-02-02T16:37:21","modified_gmt":"2022-02-02T08:37:21","slug":"leetcodeday117","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday117\/","title":{"rendered":"leetcodeday117&#8211;\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488 II"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct Node {\n  int val;\n  Node *left;\n  Node *right;\n  Node *next;\n}<\/code><\/pre>\n\n\n\n<p>\u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u8ba9\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u3002\u5982\u679c\u627e\u4e0d\u5230\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5219\u5c06 next \u6307\u9488\u8bbe\u7f6e\u4e3a&nbsp;<code>NULL<\/code>\u3002<\/p>\n\n\n\n<p>\u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6240\u6709&nbsp;next \u6307\u9488\u90fd\u88ab\u8bbe\u7f6e\u4e3a&nbsp;<code>NULL<\/code>\u3002<\/p>\n\n\n\n<p><strong>\u8fdb\u9636\uff1a<\/strong><\/p>\n\n\n\n<ul><li>\u4f60\u53ea\u80fd\u4f7f\u7528\u5e38\u91cf\u7ea7\u989d\u5916\u7a7a\u95f4\u3002<\/li><li>\u4f7f\u7528\u9012\u5f52\u89e3\u9898\u4e5f\u7b26\u5408\u8981\u6c42\uff0c\u672c\u9898\u4e2d\u9012\u5f52\u7a0b\u5e8f\u5360\u7528\u7684\u6808\u7a7a\u95f4\u4e0d\u7b97\u505a\u989d\u5916\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=117 lang=python3\r\n#\r\n# &#91;117] \u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488 II\r\n#\r\n\r\n# @lc code=start\r\n\"\"\"\r\n# Definition for a Node.\r\nclass Node:\r\n    def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):\r\n        self.val = val\r\n        self.left = left\r\n        self.right = right\r\n        self.next = next\r\n\"\"\"\r\n\r\nclass Solution:\r\n    def connect(self, root: 'Node') -> 'Node':\r\n        if not root: return root #\u6ce8\u610f\u7279\u6b8a\u60c5\u51b5\uff1a\u6811\u4e3a\u7a7a\u8fd4\u56de&#91;]\r\n        queue = &#91;root]\r\n        import copy\r\n\r\n        while queue:\r\n            lens=len(queue)\r\n            for i in range(len(queue)):\r\n                a = queue.pop(0)#\u5143\u7d20\u51fa\u961f\u5217\r\n                \r\n                a.next=queue&#91;0] if i&lt;lens-1 else None\r\n                if a.left:\r\n                    queue.append(a.left)              \r\n                if a.right:\r\n                    queue.append(a.right)\r\n    \r\n        return root\r\n# @lc code=end\r\n        \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=\"799\" height=\"255\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-11.png\" alt=\"\" class=\"wp-image-2536\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-11.png 799w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-11-300x96.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-11-768x245.png 768w\" sizes=\"(max-width: 799px) 100vw, 799px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811 \u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u8ba9\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u3002\u5982\u679c\u627e\u4e0d\u5230\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5219\u5c06  &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday117\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday117&#8211;\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488 II<\/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\/2535"}],"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=2535"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2535\/revisions"}],"predecessor-version":[{"id":2537,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2535\/revisions\/2537"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2535"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}