{"id":2568,"date":"2022-02-03T20:10:17","date_gmt":"2022-02-03T12:10:17","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2568"},"modified":"2022-02-03T20:10:19","modified_gmt":"2022-02-03T12:10:19","slug":"leetcodeday114","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/03\/leetcodeday114\/","title":{"rendered":"leetcodeday114&#8211;\u4e8c\u53c9\u6811\u5c55\u5f00\u4e3a\u94fe\u8868"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9&nbsp;<code>root<\/code>&nbsp;\uff0c\u8bf7\u4f60\u5c06\u5b83\u5c55\u5f00\u4e3a\u4e00\u4e2a\u5355\u94fe\u8868\uff1a<\/p>\n\n\n\n<ul><li>\u5c55\u5f00\u540e\u7684\u5355\u94fe\u8868\u5e94\u8be5\u540c\u6837\u4f7f\u7528&nbsp;<code>TreeNode<\/code>&nbsp;\uff0c\u5176\u4e2d&nbsp;<code>right<\/code>&nbsp;\u5b50\u6307\u9488\u6307\u5411\u94fe\u8868\u4e2d\u4e0b\u4e00\u4e2a\u7ed3\u70b9\uff0c\u800c\u5de6\u5b50\u6307\u9488\u59cb\u7ec8\u4e3a&nbsp;<code>null<\/code>&nbsp;\u3002<\/li><li>\u5c55\u5f00\u540e\u7684\u5355\u94fe\u8868\u5e94\u8be5\u4e0e\u4e8c\u53c9\u6811&nbsp;<a href=\"https:\/\/baike.baidu.com\/item\/%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86\/6442839?fr=aladdin\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>\u5148\u5e8f\u904d\u5386<\/strong><\/a>&nbsp;\u987a\u5e8f\u76f8\u540c\u3002<\/li><\/ul>\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\/01\/14\/flaten.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;1,2,5,3,4,null,6]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;1,null,2,null,3,null,4,null,5,null,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><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=114 lang=python3\r\n#\r\n# &#91;114] \u4e8c\u53c9\u6811\u5c55\u5f00\u4e3a\u94fe\u8868\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 flatten(self, root: TreeNode) -> None:\r\n        \"\"\"\r\n        Do not return anything, modify root in-place instead.\r\n        \"\"\"\r\n        nums=&#91;]\r\n        def inorder(root):\r\n            if root==None:\r\n                return \r\n            nums.append(root)\r\n            inorder(root.left)\r\n            \r\n            inorder(root.right)\r\n        if root==None:\r\n            return None\r\n        inorder(root)\r\n        root=nums&#91;0]\r\n        lens=len(nums)\r\n        for i in range(lens-1):\r\n            print(nums&#91;i].val)\r\n            nums&#91;i].left = None\r\n            nums&#91;i].right = nums&#91;i+1]\r\n        nums&#91;lens-1].left= None\r\n        nums&#91;lens-1].right=None\r\n        return root\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=\"937\" height=\"232\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-20.png\" alt=\"\" class=\"wp-image-2569\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-20.png 937w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-20-300x74.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-20-768x190.png 768w\" sizes=\"(max-width: 937px) 100vw, 937px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9&nbsp;root&nbsp;\uff0c\u8bf7\u4f60\u5c06\u5b83\u5c55\u5f00\u4e3a\u4e00\u4e2a\u5355\u94fe\u8868\uff1a \u5c55\u5f00\u540e\u7684\u5355\u94fe\u8868\u5e94\u8be5\u540c\u6837\u4f7f\u7528&#038;n &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/03\/leetcodeday114\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday114&#8211;\u4e8c\u53c9\u6811\u5c55\u5f00\u4e3a\u94fe\u8868<\/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\/2568"}],"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=2568"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2568\/revisions"}],"predecessor-version":[{"id":2570,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2568\/revisions\/2570"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2568"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}