第23860题 单选题
以下C++代码实现二叉树深度优先搜索(DFS)统计叶子结点数量,横线处应填写的内容是?
int countLeafNodes(TreeNode* root) {
    if (root == nullptr) return 0;

    stack<TreeNode*> s;
    s.push(root);
    int count = 0;
    while (!s.empty()) {
        TreeNode* node = s.top();
        s.pop();

        if (node->left == nullptr && node->right == nullptr) {
            count++;
        }

        if (node->right) s.push(node->right);
        ________________ // 在此处填入代码
    }
    return count;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析