{"id":557,"date":"2020-09-26T10:57:27","date_gmt":"2020-09-26T02:57:27","guid":{"rendered":"http:\/\/39.96.58.60\/?p=557"},"modified":"2022-10-18T16:38:54","modified_gmt":"2022-10-18T08:38:54","slug":"leetcode-589-n%e5%8f%89%e6%a0%91%e7%9a%84%e5%89%8d%e5%ba%8f%e9%81%8d%e5%8e%86","status":"publish","type":"post","link":"https:\/\/www.yatenglg.cn\/blog\/?p=557","title":{"rendered":"Leetcode 589. N\u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386"},"content":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684<em>\u524d\u5e8f\u904d\u5386<\/em>\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u7ed9\u5b9a\u4e00\u4e2a&nbsp;<code>3\u53c9\u6811<\/code>&nbsp;:<\/p>\n<p>&nbsp;<\/p>\n<p><img src=\"https:\/\/assets.leetcode-cn.com\/aliyun-lc-upload\/uploads\/2018\/10\/12\/narytreeexample.png\" style=\"width: 100%; max-width: 300px;\"><\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd4\u56de\u5176\u524d\u5e8f\u904d\u5386: <code>[1,3,5,6,2,4]<\/code>\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u8bf4\u660e:&nbsp;<\/strong>\u9012\u5f52\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fed\u4ee3\u6cd5\u5b8c\u6210\u6b64\u9898\u5417?<\/p>\n<p>**\u96be\u5ea6**: Easy<\/p>\n<p>**\u6807\u7b7e**: \u6811\u3001<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code>\n# -*- coding: utf-8 -*-\n# @Author  : LG\n\n\"\"\"\n\u6267\u884c\u7528\u65f6\uff1a60 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8686.96% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a15.2 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8685.68% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u9012\u5f52\n\"\"\"\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 preorder(self, root: 'Node') -&gt; List[int]:\n        result =[]\n        def find(root):\n            if root:\n                result.append(root.val)\n                childrens = root.children\n                for children in childrens:\n                    find(children)\n        find(root)\n        return result<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684\u524d\u5e8f\u904d\u5386\u3002 \u4f8b\u5982\uff0c\u7ed9\u5b9a\u4e00\u4e2a&nbsp;3\u53c9\u6811&nbsp;: &nbsp; &#038;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/557"}],"collection":[{"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=557"}],"version-history":[{"count":1,"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/557\/revisions"}],"predecessor-version":[{"id":558,"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/557\/revisions\/558"}],"wp:attachment":[{"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}