题目链接:
https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
//1. input and root , add 1 to the depth ,untill ,it reach the leaf
int maxDepth(TreeNode* root) {
return root == NULL ? 0:max(maxDepth(root->left),maxDepth(root->right)) +1 ;
}
};