Skip to content

Instantly share code, notes, and snippets.

@MorrisLaw
Created June 2, 2022 11:02
Show Gist options
  • Save MorrisLaw/07fb492aeb8c77c8186c706f801b6cb5 to your computer and use it in GitHub Desktop.
Save MorrisLaw/07fb492aeb8c77c8186c706f801b6cb5 to your computer and use it in GitHub Desktop.
Maximum Depth of Binary Tree - LeetCode 104
func maxDepth(root *TreeNode) int {
if root == nil {
return 0
}
return max(maxDepth(root.Left), maxDepth(root.Right)) + 1
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment