104. 二叉树的最大深度c

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int max(int i,int j){
if(i>j) return i ;
return j;
}
int maxDepth(struct TreeNode* root) {
if(!root) return 0;
return max(maxDepth(root->left),maxDepth(root->right))+1;
}
结果:

浙公网安备 33010602011771号