mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Merge pull request #2015 from L-evi/master
补充0111.二叉树的最小深度中的关于前序遍历(中左右)的中处理逻辑
This commit is contained in:
@ -170,11 +170,14 @@ class Solution {
|
||||
private:
|
||||
int result;
|
||||
void getdepth(TreeNode* node, int depth) {
|
||||
if (node->left == NULL && node->right == NULL) {
|
||||
result = min(depth, result);
|
||||
// 函数递归终止条件
|
||||
if (root == nullptr) {
|
||||
return;
|
||||
}
|
||||
// 中 只不过中没有处理的逻辑
|
||||
// 中,处理逻辑:判断是不是叶子结点
|
||||
if (root -> left == nullptr && root->right == nullptr) {
|
||||
res = min(res, depth);
|
||||
}
|
||||
if (node->left) { // 左
|
||||
getdepth(node->left, depth + 1);
|
||||
}
|
||||
@ -186,7 +189,9 @@ private:
|
||||
|
||||
public:
|
||||
int minDepth(TreeNode* root) {
|
||||
if (root == NULL) return 0;
|
||||
if (root == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
result = INT_MAX;
|
||||
getdepth(root, 1);
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user