4 lines java code solving problem


  • 6
    D
    public class Solution {
        public int maxDepth(TreeNode root) {
            if (root == null)  return 0;
            int leftDepth = maxDepth(root.left);
            int rightDepth = maxDepth(root.right);
            return leftDepth > rightDepth ? leftDepth + 1 : rightDepth + 1;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.