8ms C++ Depth-First-Search solution


  • 0
    J
    int maxDepth(TreeNode* root) {
        int num = 0;
        if(root){  
            num = 1; 
            int left = 0;
            int right = 0;
            left = maxDepth(root->left);  
            right = maxDepth(root->right);  
            if(left > right)
                num += left;
            else
                num += right;
        }
        return num;
    }

Log in to reply
 

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