-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximum_depth.cpp
More file actions
52 lines (46 loc) · 1.05 KB
/
maximum_depth.cpp
File metadata and controls
52 lines (46 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* =====================================================================================
*
* Filename: maximum_depth.cpp
*
* Description: Maximum Depth of Binary Tree
*
* Version: 1.0
* Created: 02/20/19 13:04:35
* Revision: none
* Compiler: gcc
*
* Author: Zhu Xianfeng (), xianfeng.zhu@gmail.com
* Organization:
*
* =====================================================================================
*/
#include <stdio.h>
struct TreeNode
{
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
int maxDepth(TreeNode* root)
{
if (root == NULL)
{
return 0;
}
int a = maxDepth(root->left) + 1;
int b = maxDepth(root->right) + 1;
return (a > b ? a : b);
}
};
int main(int argc, char* argv[])
{
TreeNode* root = NULL;
auto depth = Solution().maxDepth(root);
printf("Maximum depth of binary tree? %d\n", depth);
return 0;
}