104. Maximum Depth of Binary Tree Posted on 2021-01-20 Edited on 2021-01-25 In LeetCode Disqus: Symbols count in article: 341 Reading time ≈ 1 mins. dfs O(n) time O(h) space 123456789101112131415/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int maxDepth(TreeNode* root) { return root ? max(maxDepth(root->left), maxDepth(root->right)) + 1 : 0; }};