/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/funcfindBottomLeftValue(root*TreeNode)int{res,maxDepth:=root,0vardfsfunc(root*TreeNode,depthint)dfs=func(root*TreeNode,depthint){ifroot!=nil{depth+=1ifroot.Left==nil&&root.Right==nil{// 只有当 depth > maxDepth 时才更新 res
ifdepth>maxDepth{maxDepth=depthres=root}return}// 为了确保是最左边节点的值,需要先遍历左子树!
dfs(root.Left,depth)dfs(root.Right,depth)}}dfs(root,0)returnres.Val}