1. 二叉树的最大深度
- 给定一个二叉树
root,返回其最大深度。二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。
输入:root = [3,9,20,null,null,15,7]
输出:3
1 | # Definition for a binary tree node. |
1 | # Definition for a binary tree node. |
2. 相同的树
- (100)给你两棵二叉树的根节点
p和q,编写一个函数来检验这两棵树是否相同。如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。
输入:p = [1,2,3], q = [1,2,3]
输出:true
1 | # Definition for a binary tree node. |
3. 对称二叉树
- (101)给你一个二叉树的根节点
root, 检查它是否轴对称。
输入:root = [1,2,2,3,4,4,3]
输出:true
1 | # Definition for a binary tree node. |
4. 平衡二叉树
- 给定一个二叉树,判断它是否是 平衡二叉树 。平衡二叉树 是指该树所有节点的左右子树的高度相差不超过 1。
输入:root = [3,9,20,null,null,15,7]
输出:true
1 | # Definition for a binary tree node. |
5. 二叉树的右视图
- (199)给定一个二叉树的 根节点
root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。
输入:root = [1,2,3,null,5,null,4]
输出:[1,3,4]
1 | # Definition for a binary tree node. |