Created
June 2, 2022 11:02
-
-
Save MorrisLaw/07fb492aeb8c77c8186c706f801b6cb5 to your computer and use it in GitHub Desktop.
Maximum Depth of Binary Tree - LeetCode 104
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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