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