# 104. Maximum Depth of Binary Tree Difficulty: Easy ## Solution ```cpp= /** *** Author: R-CO *** E-mail: daniel1820kobe@gmail.com *** Date: 2020-10-15 **/ #include <algorithm> #include <cstdlib> 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 { public: int maxDepth(TreeNode *root) { int depth = 0; depth = findMaxDepth(root, depth); return depth; } private: int findMaxDepth(TreeNode *node, int depth) { if (node == nullptr) { return depth; } ++depth; return std::max(findMaxDepth(node->left, depth), findMaxDepth(node->right, depth)); } }; int main(int argc, char *argv[]) { return EXIT_SUCCESS; } ``` ## Result Success Details Runtime: 8 ms, faster than 94.69% of C++ online submissions for Maximum Depth of Binary Tree. Memory Usage: 19.5 MB, less than 9.04% of C++ online submissions for Maximum Depth of Binary Tree. ###### tags: `LeetCode-Easy` `C++`