diff --git a/problems/0111.二叉树的最小深度.md b/problems/0111.二叉树的最小深度.md index de36c6f2..47569b05 100644 --- a/problems/0111.二叉树的最小深度.md +++ b/problems/0111.二叉树的最小深度.md @@ -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;