From 393ddb83df59c398f327858b85a16c031839db16 Mon Sep 17 00:00:00 2001 From: Sainnhe Park Date: Mon, 30 Jan 2023 20:55:48 +0800 Subject: [PATCH] s0104 --- include/s0104_maximum_depth_of_binary_tree.hpp | 15 +++++++++++++++ src/s0104_maximum_depth_of_binary_tree.cpp | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 include/s0104_maximum_depth_of_binary_tree.hpp create mode 100644 src/s0104_maximum_depth_of_binary_tree.cpp 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; +}