{"id":2553,"date":"2022-02-02T18:17:18","date_gmt":"2022-02-02T10:17:18","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2553"},"modified":"2022-02-02T18:17:19","modified_gmt":"2022-02-02T10:17:19","slug":"leetcodeday103","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday103\/","title":{"rendered":"leetcodeday103&#8211;\u4e8c\u53c9\u6811\u7684\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386"},"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\u7684&nbsp;<strong>\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386<\/strong>&nbsp;\u3002\uff08\u5373\u5148\u4ece\u5de6\u5f80\u53f3\uff0c\u518d\u4ece\u53f3\u5f80\u5de6\u8fdb\u884c\u4e0b\u4e00\u5c42\u904d\u5386\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u5c42\u4e0e\u5c42\u4e4b\u95f4\u4ea4\u66ff\u8fdb\u884c\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\/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;3],&#91;20,9],&#91;15,7]]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=103 lang=python3\r\n#\r\n# &#91;103] \u4e8c\u53c9\u6811\u7684\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386\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 zigzagLevelOrder(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        rev=True\r\n        while queue:\r\n            list2 = &#91;]\r\n            \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            if rev!=True:\r\n                list2.reverse()\r\n            list1.append(list2)\r\n            rev=not rev\r\n           \r\n        return list1\r\n# @lc code=end\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"964\" height=\"234\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-16.png\" alt=\"\" class=\"wp-image-2555\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-16.png 964w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-16-300x73.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-16-768x186.png 768w\" sizes=\"(max-width: 964px) 100vw, 964px\" \/><\/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\u7684&nbsp;\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386&nbsp;\u3002\uff08\u5373 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday103\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday103&#8211;\u4e8c\u53c9\u6811\u7684\u952f\u9f7f\u5f62\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\/2553"}],"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=2553"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2553\/revisions"}],"predecessor-version":[{"id":2556,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2553\/revisions\/2556"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2553"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}