Maximum Depth of Binary Tree

xiaoxiao2021-02-28  64

/**  * 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 depth_left=maxDepth(root->left);         int depth_right=maxDepth(root->right);         return depth_left>depth_right?depth_left+1:depth_right+1;              } };
转载请注明原文地址: https://www.6miu.com/read-75576.html

最新回复(0)