Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CollinShoop/84f25dbc298770c7d763b163f393e7d0 to your computer and use it in GitHub Desktop.
Save CollinShoop/84f25dbc298770c7d763b163f393e7d0 to your computer and use it in GitHub Desktop.
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
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