{"id":2525,"date":"2022-02-02T15:28:07","date_gmt":"2022-02-02T07:28:07","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2525"},"modified":"2022-02-02T15:28:08","modified_gmt":"2022-02-02T07:28:08","slug":"leetcodeday429","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday429\/","title":{"rendered":"leetcodeday429&#8212; N \u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684<em>\u5c42\u5e8f\u904d\u5386<\/em>\u3002\uff08\u5373\u4ece\u5de6\u5230\u53f3\uff0c\u9010\u5c42\u904d\u5386\uff09\u3002<\/p>\n\n\n\n<p>\u6811\u7684\u5e8f\u5217\u5316\u8f93\u5165\u662f\u7528\u5c42\u5e8f\u904d\u5386\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u90fd\u7531 null \u503c\u5206\u9694\uff08\u53c2\u89c1\u793a\u4f8b\uff09\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/assets.leetcode.com\/uploads\/2018\/10\/12\/narytreeexample.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;1,null,3,2,4,null,5,6]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;&#91;1],&#91;3,2,4],&#91;5,6]]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># &#91;429] N \u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386\n#\n\n# @lc code=start\n\"\"\"\n# Definition for a Node.\nclass Node:\n    def __init__(self, val=None, children=None):\n        self.val = val\n        self.children = children\n\"\"\"\n\nclass Solution:\n    def levelOrder(self, root: 'Node') -&gt; List&#91;List&#91;int]]:\n        if not root: return &#91;] #\u6ce8\u610f\u7279\u6b8a\u60c5\u51b5\uff1a\u6811\u4e3a\u7a7a\u8fd4\u56de&#91;]\n        queue = &#91;root]\n        list1 = &#91;]\n        while queue:\n            list2 = &#91;]\n            lens=len(queue)\n            for i in range(lens):\n                a = queue.pop(0)#\u5143\u7d20\u51fa\u961f\u5217\n                for i in range(len(a.children)):\n                    queue.append(a.children&#91;i])\n                     \n                list2.append(a.val)\n            list1.append(list2)\n        return list1\n\n        \n# @lc code=end\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"820\" height=\"231\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-8.png\" alt=\"\" class=\"wp-image-2527\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-8.png 820w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-8-300x85.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-8-768x216.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684\u5c42\u5e8f\u904d\u5386\u3002\uff08\u5373\u4ece\u5de6\u5230\u53f3\uff0c\u9010\u5c42\u904d\u5386\uff09\u3002 \u6811\u7684\u5e8f\u5217\u5316\u8f93\u5165\u662f\u7528\u5c42\u5e8f\u904d\u5386\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday429\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday429&#8212; N \u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386<\/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\/2525"}],"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=2525"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2525\/revisions"}],"predecessor-version":[{"id":2528,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2525\/revisions\/2528"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2525"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}