diff --git a/include/s0104_maximum_depth_of_binary_tree.hpp b/include/s0104_maximum_depth_of_binary_tree.hpp new file mode 100644 index 0000000..e360194 --- /dev/null +++ b/include/s0104_maximum_depth_of_binary_tree.hpp @@ -0,0 +1,15 @@ +#ifndef S0104_MAXIMUM_DEPTH_OF_BINARY_TREE_HPP +#define S0104_MAXIMUM_DEPTH_OF_BINARY_TREE_HPP + +#include + +#include "structures.hpp" + +using namespace std; + +class S0104 { + public: + int maxDepth(TreeNode* root); +}; + +#endif diff --git a/src/s0104_maximum_depth_of_binary_tree.cpp b/src/s0104_maximum_depth_of_binary_tree.cpp new file mode 100644 index 0000000..387b175 --- /dev/null +++ b/src/s0104_maximum_depth_of_binary_tree.cpp @@ -0,0 +1,6 @@ +#include "s0104_maximum_depth_of_binary_tree.hpp" + +int S0104::maxDepth(TreeNode* root) { + if (root == nullptr) return 0; + return max(maxDepth(root->left), maxDepth(root->right)) + 1; +}