LeetCode | 104. Maximum depth of binary tree
- One thing to note here is that every time there is a return value, you need to define a variable to save the last value.
- Finally take the highest oneAdd 1
int maxDepth(struct TreeNode* root) {
if(root == NULL)
return NULL;
int left = maxDepth(root->left);
int right = maxDepth(root->right);
return left > right ? left + 1 : right + 1;
}