Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TreeNode {
- int val;
- TreeNode left;
- TreeNode right;
- TreeNode(int x) { val = x; }
- }
- public class Solution {
- public int maxDepth(TreeNode root) {
- int depth = 1;
- if (root.left != null)
- depth = Math.max(depth, maxDepth(root.left) + 1);
- if (root.right != null)
- depth = Math.max(depth, maxDepth(root.right) + 1);
- return depth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement