剑指 Offer 55 - I. 二叉树的深度
作者:互联网
/**
* 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:
int maxDepth(TreeNode* root) {
if(root==NULL) return 0;
int left = maxDepth( root->left);
int right = maxDepth( root->right);
return (left>right? left:right) + 1;
}
};
标签:right,TreeNode,Offer,55,int,二叉树,maxDepth,root,left 来源: https://blog.csdn.net/qq_42133142/article/details/120575880