Skip to content

Commit a6c06f7

Browse files
authored
Create 张小胖.md
1 parent 559de1b commit a6c06f7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

2018.12.07-leetcode104/张小胖.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)