Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbe0bfa

Browse files
committed
Time: 9 ms (32.83%), Space: 18.9 MB (39.60%) - LeetHub
1 parent 5186f8c commit bbe0bfa

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
8+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
9+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
10+
* };
11+
*/
12+
class Solution {
13+
public:
14+
int maxDepth(TreeNode* root)
15+
{
16+
if(root==NULL)
17+
return 0;
18+
int lh=maxDepth(root->left);
19+
int rh= maxDepth(root->right);
20+
21+
return 1+max(lh,rh);
22+
23+
}
24+
};

0 commit comments

Comments
 (0)