We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 559de1b + a6c06f7 commit 4f8aba5Copy full SHA for 4f8aba5
2018.12.07-leetcode104/张小胖.md
@@ -0,0 +1,19 @@
1
+ /**
2
+ Definition for a binary tree node.
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
+ if(root==nullptr) return 0;
14
+ int leftDepth=maxDepth(root->left);
15
+ int rightDepth=maxDepth(root->right);
16
+ if(leftDepth>rightDepth) return leftDepth+1;
17
+ else return rightDepth+1;
18
+ }
19
0 commit comments