2025每日刷题(244)
Leetcode---513. 找树左下角的值

实现代码
go
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func findBottomLeftValue(root *TreeNode) int {
maxDepth := 0
ans := 0
dfs(root, &maxDepth, 1, &ans)
return ans
}
func dfs(root *TreeNode, maxDepth *int, depth int, ans *int) {
if root == nil {
return
}
if *maxDepth < depth {
*maxDepth = depth
*ans = root.Val
}
dfs(root.Left, maxDepth, depth + 1, ans)
dfs(root.Right, maxDepth, depth + 1, ans)
}
运行结果

之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!