Java Solution Using Recursion


  • 0
    R
    public static int maxDepth(Node<Interger> node)  {
        if(node == null) 
            return 0;
        if(node.getLeftChild() == null && node.getRightChild() == null)
            return 0;
        int leftPathDepth  = 1 + maxDepth(head.getLeftChild());
        int rightPathDepth = 1 + maxDepth(head.getRightChild());
            return Math.max(leftPathDepth,rightPathDepth)
        
    }
    

Log in to reply
 

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