1. 题解
不管是前序遍历,mid遍历,还是后续遍历.最深的第一个出现的节点一定是最左节点.
//32. 最底层最左边节点
int maxDeptInfindBottomLeftValue=0;
int resValue=0;
public int findBottomLeftValue(TreeNode root) {
if (root==null){
return 0;
}
findBottomLeftValue(root,1);
return resValue;
}
public void findBottomLeftValue(TreeNode root,int dept) {// 我的深度
if (root==null){
return ;
}
if (dept>maxDeptInfindBottomLeftValue){
maxDeptInfindBottomLeftValue=dept;
resValue=root.val;
}
findBottomLeftValue(root.left,dept+1);
findBottomLeftValue(root.right,dept+1);
}
}