s0111
ci/woodpecker/push/test Pipeline was successful Details

This commit is contained in:
Sainnhe Park 2023-01-30 21:00:44 +08:00
parent 393ddb83df
commit 38d44a6fa8
2 changed files with 27 additions and 0 deletions

View File

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

View File

@ -0,0 +1,12 @@
#include "s0111_minimum_depth_of_binary_tree.hpp"
int S0111::minDepth(TreeNode* root) {
if (root == nullptr) return 0;
if (root->left == nullptr && root->right != nullptr) {
return minDepth(root->right) + 1;
} else if (root->left != nullptr && root->right == nullptr) {
return minDepth(root->left) + 1;
} else {
return min(minDepth(root->left), minDepth(root->right)) + 1;
}
}