Last active
March 14, 2018 16:19
-
-
Save nleiva/aa12dc62cc1e701c694add310af3aa52 to your computer and use it in GitHub Desktop.
Maximum Depth of Binary Tree (104) from https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
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 | |
} | |
d := 1 + max(maxDepth(root.Right), maxDepth(root.Left)) | |
return d | |
} | |
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