root->left = node;
}else if(root->right == nullptr) {
root->right = node;
//队列加入两个左右节点并去除根节点
q.push(root->left);
q.push(root->right);
q.pop();
}
return root->val;
}
TreeNode* get_root() {
return root;
}
};
=========================================================================================
题目:
给定一棵二叉树的根节点
root
,请找出该二叉树中每一层的最大值。
示例:
输入: root = [1,3,2,5,3,null,9]
输出: [1,3,9]
提示:
-
二叉树的节点个数的范围是
[0,104]
-
-231 <= Node.val <= 231 - 1
思路: