Created
August 17, 2018 15:07
-
-
Save yohey03518/111058022af5df209a8d55d4d81669c9 to your computer and use it in GitHub Desktop.
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
public int MaxDepth(TreeNode root) | |
{ | |
if (root.left == null && root.right == null) | |
return 1; | |
int maxDepthLeft = 0, maxDepthRight = 0; | |
if (root.left != null) | |
maxDepthLeft = 1 + MaxDepth(root.left); | |
if (root.right != null) | |
maxDepthRight = 1 + MaxDepth(root.right); | |
if (maxDepthLeft > maxDepthRight) | |
return maxDepthLeft; | |
else | |
return maxDepthRight; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment