{"id":2511,"date":"2022-02-02T14:09:38","date_gmt":"2022-02-02T06:09:38","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2511"},"modified":"2022-02-02T14:09:38","modified_gmt":"2022-02-02T06:09:38","slug":"leetcodeday-3","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday-3\/","title":{"rendered":"leetcodeday&#8211;[107] \u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386 II"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;<code>root<\/code>&nbsp;\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c&nbsp;<strong>\u81ea\u5e95\u5411\u4e0a\u7684\u5c42\u5e8f\u904d\u5386<\/strong>&nbsp;\u3002 \uff08\u5373\u6309\u4ece\u53f6\u5b50\u8282\u70b9\u6240\u5728\u5c42\u5230\u6839\u8282\u70b9\u6240\u5728\u7684\u5c42\uff0c\u9010\u5c42\u4ece\u5de6\u5411\u53f3\u904d\u5386\uff09<\/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\/2021\/02\/19\/tree1.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;3,9,20,null,null,15,7]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;&#91;15,7],&#91;9,20],&#91;3]]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;1]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;&#91;1]]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=107 lang=python3\r\n#\r\n# &#91;107] \u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386 II\r\n#\r\n\r\n# @lc code=start\r\n# Definition for a binary tree node.\r\n# class TreeNode:\r\n#     def __init__(self, val=0, left=None, right=None):\r\n#         self.val = val\r\n#         self.left = left\r\n#         self.right = right\r\nclass Solution:\r\n    def levelOrderBottom(self, root: TreeNode) -> List&#91;List&#91;int]]:\r\n        if not root: return &#91;] #\u6ce8\u610f\u7279\u6b8a\u60c5\u51b5\uff1a\u6811\u4e3a\u7a7a\u8fd4\u56de&#91;]\r\n        queue = &#91;root]\r\n        list1 = &#91;]\r\n        while queue:\r\n            list2 = &#91;]\r\n            for i in range(len(queue)):\r\n                a = queue.pop(0)#\u5143\u7d20\u51fa\u961f\u5217\r\n                if a.left:\r\n                    queue.append(a.left)\r\n                if a.right:\r\n                    queue.append(a.right)\r\n                list2.append(a.val)\r\n            list1.append(list2)\r\n        list1.reverse()\r\n        return list1\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=\"820\" height=\"235\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-4.png\" alt=\"\" class=\"wp-image-2512\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-4.png 820w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-4-300x86.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-4-768x220.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;root&nbsp;\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c&nbsp;\u81ea\u5e95\u5411\u4e0a\u7684\u5c42\u5e8f\u904d\u5386&nbsp;\u3002  &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday-3\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday&#8211;[107] \u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386 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\/2511"}],"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=2511"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2511\/revisions"}],"predecessor-version":[{"id":2513,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2511\/revisions\/2513"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2511"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}