Skip to content

Commit 08c40f5

Browse files
authored
Create MQQM.cpp
1 parent 5a145d2 commit 08c40f5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

2018.12.07-leetcode104/MQQM.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
题目:
3+
给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数
4+
*/
5+
6+
/**
7+
* Definition for a binary tree node.
8+
* struct TreeNode {
9+
* int val;
10+
* TreeNode *left;
11+
* TreeNode *right;
12+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
13+
* };
14+
*/
15+
class Solution {
16+
public:
17+
int maxDepth(TreeNode* root) {
18+
if(root==NULL)
19+
return 0;
20+
int leftDepth = maxDepth(root->left);
21+
int rightDepth = maxDepth(root->right);
22+
return (leftDepth > rightDepth) ? leftDepth+1 : rightDepth+1 ;
23+
}
24+
};

0 commit comments

Comments
 (0)