-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day-080.cpp
33 lines (32 loc) · 952 Bytes
/
Day-080.cpp
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
/**
* Definition for a binary tree node.
* struct TreeNode {
* char val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val('0'), left(nullptr), right(nullptr) {}
* TreeNode(char x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(char x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
int deepest_height;
char character;
void getDeepestHeight(TreeNode* root, int current_height) {
if (root == nullptr) {
return ;
}
if (deepest_height < current_height) {
deepest_height = current_height;
character = root -> val;
}
getDeepestHeight(root -> right, current_height+1);
getDeepestHeight(root -> left, current_height+1);
}
public:
char maxDepth(TreeNode* root) {
deepest_height=0;
getDeepestHeight(root, 1);
return character;
}
};