It is simple, it is clean because it is recursive. Nothing much to understand.

  • 5
    public int maxDepth(TreeNode root) {
        if(root == null)
            return 0;
        return 1 + max(maxDepth(root.left), maxDepth(root.right));
    private int max(int a, int b){
        return a>b?a:b;

Log in to reply

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