LeetCode 104. Maximum Depth of Binary

第二次

class Solution 
{
public:
    int maxDepth(TreeNode *root) 
    {
        return root==NULL? 0:
            1 + max(maxDepth(root->left), maxDepth(root->right));
    }
};


第一次:

class Solution 
{
public:
    int maxDepth(TreeNode *root) 
    {
    	if (root == NULL)
    	{
    		return 0;
    	} else 
    	{
    		return 1 + max(maxDepth(root->left), maxDepth(root->right));
    	}
    }
};


你可能感兴趣的:(LeetCode,C++,tree,maximum,depth)