给定一棵二叉树的根节点 root
,请找出该二叉树中每一层的最大值。
示例1:
输入: root = [1,3,2,5,3,null,9] 输出: [1,3,9] 解释: 1 / \ 3 2 / \ \ 5 3 9
示例2:
输入: root = [1,2,3] 输出: [1,3] 解释: 1 / \ 2 3
示例3:
输入: root = [1] 输出: [1]
示例4:
输入: root = [1,null,2] 输出: [1,2] 解释: 1 \ 2
示例5:
输入: root = [] 输出: []
提示:
[0,104]
-231 <= Node.val <= 231 - 1
注意:本题与主站 515 题相同: https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/