s0104
This commit is contained in:
parent
2ba7e17b1c
commit
393ddb83df
15
include/s0104_maximum_depth_of_binary_tree.hpp
Normal file
15
include/s0104_maximum_depth_of_binary_tree.hpp
Normal 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
|
6
src/s0104_maximum_depth_of_binary_tree.cpp
Normal file
6
src/s0104_maximum_depth_of_binary_tree.cpp
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user