Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. public class TreeNode {
  2. int val;
  3. TreeNode left;
  4. TreeNode right;
  5. TreeNode(int x) { val = x; }
  6. }
  7.  
  8. public class Solution {
  9. public int maxDepth(TreeNode root) {
  10. int depth = 1;
  11. if (root.left != null)
  12. depth = Math.max(depth, maxDepth(root.left) + 1);
  13. if (root.right != null)
  14. depth = Math.max(depth, maxDepth(root.right) + 1);
  15. return depth;
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement