/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
private:
int height = 0;
public:
void findHeight(TreeNode *node, int depth) {
if(node == NULL) return;
if(depth > height) height = depth;
if(node->left != NULL) findHeight(node->left, depth + 1);
if(node->right != NULL) findHeight(node->right, depth + 1);
}
int maxDepth(TreeNode* root) {
if(root == NULL) return 0;
findHeight(root, 1);
return height;
}
};