Maximum Depth of Binary Tree
Solution in go

DFS

func maxDepth(root *TreeNode) int {
    if root == nil {
        return 0
    }

    left := maxDepth(root.Left) + 1
    right := maxDepth(root.Right) + 1

    if left > right {
        return left
    }

    return right
}
    TheDeveloperCafe © 2022-2024