Skip to content

Commit 70de3ea

Browse files
committed
1
1 parent d9d2226 commit 70de3ea

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Definition for binary tree
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
public:
12+
int maxDepth(TreeNode *root) {
13+
// Start typing your C/C++ solution below
14+
// DO NOT write int main() function
15+
if (root == NULL)
16+
return 0;
17+
int lf = 1 + maxDepth(root->left);
18+
int rt = 1 + maxDepth(root->right);
19+
return max(lf, rt);
20+
}
21+
};

0 commit comments

Comments
 (0)