加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

[LeetCode]Smallest Subtree with all the Deepest Nodes 包含最

发布时间:2020-12-14 04:33:40 所属栏目:大数据 来源:网络整理
导读:Given a binary tree rooted at? root ,the? depth ?of each node is the shortest distance to the root. A node is? deepest ?if it has the largest depth possible among?any node in the?entire tree. The subtree of a node is that node,plus the set



Given a binary tree rooted at?root,the?depth?of each node is the shortest distance to the root.

A node is?deepest?if it has the largest depth possible among?any node in the?entire tree.

The subtree of a node is that node,plus the set of all descendants of that node.

Return the node with the largest depth such that it contains all the deepest nodes in its subtree.

Example 1:

Input: [3,5,1,6,2,8,null,7,4]
Output: [2,4]
Explanation:

We return the node with value 2,colored in yellow in the diagram.
The nodes colored in blue are the deepest nodes of the tree.
The input "[3,4]" is a serialization of the given tree.
The output "[2,4]" is a serialization of the subtree rooted at the node with value 2.
Both the input and output have TreeNode type.

Note:

  • The number of nodes in the tree will be between 1 and 500.
  • The values of each node are unique.



参考资料:

https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/



LeetCode All in One 题目讲解汇总(持续更新中...)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读