This commit is contained in:
Sainnhe Park 2023-01-30 20:55:48 +08:00
parent 2ba7e17b1c
commit 393ddb83df
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#ifndef S0104_MAXIMUM_DEPTH_OF_BINARY_TREE_HPP
#define S0104_MAXIMUM_DEPTH_OF_BINARY_TREE_HPP
#include <algorithm>
#include "structures.hpp"
using namespace std;
class S0104 {
public:
int maxDepth(TreeNode* root);
};
#endif

View File

@ -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;
}