1.求一个二叉树的高度
public static int getMaxDepth(TreeNode root){
if(root == null){
return 0;
}
int left = getMaxDepth(root.left);
int right = getMaxDepth(root.right);
return Math.max(left,right)+1;
}
2.前序遍历二叉树
在这里插入代码片
1.求一个二叉树的高度
public static int getMaxDepth(TreeNode root){
if(root == null){
return 0;
}
int left = getMaxDepth(root.left);
int right = getMaxDepth(root.right);
return Math.max(left,right)+1;
}
2.前序遍历二叉树
在这里插入代码片