Skip to content

Commit c7851e1

Browse files
committed
Time: 18 ms (15.01%), Space: 18.8 MB (55.51%) - LeetHub
1 parent fb4ac04 commit c7851e1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 h = 0;
15+
int maxDepth(TreeNode* root) {
16+
if(!root) {
17+
h = 0;
18+
return 0;
19+
}
20+
h = max(maxDepth(root->left), maxDepth(root->right))+1;
21+
return h;
22+
}
23+
};

0 commit comments

Comments
 (0)