Skip to content

Commit 98120c6

Browse files
authored
Merge pull request gzc426#353 from GatesMa/patch-14
Create GatesMa.md
2 parents 975a101 + 7e52117 commit 98120c6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

2018.12.07-leetcode104/GatesMa.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# c++
2+
```cpp
3+
/**
4+
* Definition for a binary tree node.
5+
* struct TreeNode {
6+
* int val;
7+
* TreeNode *left;
8+
* TreeNode *right;
9+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
10+
* };
11+
*/
12+
class Solution {
13+
public:
14+
int maxDepth(TreeNode* root) {
15+
return depth(root);
16+
}
17+
int depth(TreeNode* root) {
18+
if(root == NULL) return 0;
19+
int l = depth(root->left);
20+
int r = depth(root->right);
21+
return l > r ? l + 1 : r + 1;
22+
}
23+
};
24+
```

0 commit comments

Comments
 (0)