Skip to content

Commit bd2cb5a

Browse files
committed
AC maxDepth
1 parent 534705d commit bd2cb5a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: P104.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "header.h"
2+
3+
class Solution {
4+
public:
5+
int maxDepth(TreeNode* root) {
6+
return f(root,1);
7+
}
8+
int f(TreeNode* t, int l) {
9+
if (!t) return l-1;
10+
return max(f(t->left,l+1),f(t->right,l+1));
11+
}
12+
13+
};
14+
15+
int main() {
16+
cout << Solution().maxDepth(NULL);
17+
return 0;
18+
}

0 commit comments

Comments
 (0)