{"id":2529,"date":"2022-02-02T15:31:11","date_gmt":"2022-02-02T07:31:11","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2529"},"modified":"2022-02-02T15:31:12","modified_gmt":"2022-02-02T07:31:12","slug":"leetcodeday515","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/02\/leetcodeday515\/","title":{"rendered":"leetcodeday515&#8211;\u5728\u6bcf\u4e2a\u6811\u884c\u4e2d\u627e\u6700\u5927\u503c"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;<code>root<\/code>&nbsp;\uff0c\u8bf7\u627e\u51fa\u8be5\u4e8c\u53c9\u6811\u4e2d\u6bcf\u4e00\u5c42\u7684\u6700\u5927\u503c\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/assets.leetcode.com\/uploads\/2020\/08\/21\/largest_e1.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165: <\/strong>root = &#91;1,3,2,5,3,null,9]\n<strong>\u8f93\u51fa: <\/strong>&#91;1,3,9]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165: <\/strong>root = &#91;1,2,3]\n<strong>\u8f93\u51fa: <\/strong>&#91;1,3]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=515 lang=python3\r\n#\r\n# &#91;515] \u5728\u6bcf\u4e2a\u6811\u884c\u4e2d\u627e\u6700\u5927\u503c\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 largestValues(self, root: Optional&#91;TreeNode]) -> 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 = -2**31\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=max(list2,a.val)\r\n            list1.append(list2)\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=\"879\" height=\"206\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-9.png\" alt=\"\" class=\"wp-image-2530\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-9.png 879w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-9-300x70.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-9-768x180.png 768w\" sizes=\"(max-width: 879px) 100vw, 879px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;root&nbsp;\uff0c\u8bf7\u627e\u51fa\u8be5\u4e8c\u53c9\u6811\u4e2d\u6bcf\u4e00\u5c42\u7684\u6700\u5927\u503c\u3002 \u793a\u4f8b1\uff1a \u793a\u4f8b2\uff1a<\/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\/2529"}],"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=2529"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2529\/revisions"}],"predecessor-version":[{"id":2531,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2529\/revisions\/2531"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2529"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}