Skip to content

【每日一题】- 2019-08-09 - 96. 不同的二叉搜索树 #90

Closed
@azl397985856

Description

@azl397985856

给你一个有根节点的二叉树,找到它最深的叶节点的最近公共祖先。

回想一下:

叶节点 是二叉树中没有子节点的节点
树的根节点的 深度 为 0,如果某一节点的深度为 d,那它的子节点的深度就是 d+1
如果我们假定 A 是一组节点 S 的 最近公共祖先,S中的每个节点都在以 A 为根节点的子树中,且 A 的深度达到此条件下可能的最大值。
 

示例 1:

输入:root = [1,2,3]
输出:[1,2,3]
示例 2:
Explanation:
The deepest leaves are the nodes with values 2 and 3.
The lowest common ancestor of these leaves is the node with value 1.
The answer returned is a TreeNode object (not an array) with serialization "[1,2,3]".

输入:root = [1,2,3,4]
输出:[4]
示例 3:

输入:root = [1,2,3,4,5]
输出:[2,4,5]
 

提示:

给你的树中将有 1 到 1000 个节点。
树中每个节点的值都在 1 到 1000 之间。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions