C++ Solution using recursion


  • 0
    I

    class Solution {
    public:

    int maxDepth(TreeNode* root) {
    	if (root == nullptr)
    	{
    		return 0;
    	}
    
    	return Max(maxDepth(root->left), maxDepth(root->right)) + 1;
    }
    
    int Max(int a, int b)
    {
    	if (a > b)
    	{
    		return a;
    	}
    
    	return b;
    }
    

    };


Log in to reply
 

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