‹ 上一题 下一题 ›

g6-05202. GESP-6级-2026-06-单选-第06题 未做

以下函数 check() 用于判断一棵二叉树是否为( )。

bool check(TreeNode* root) {
    if (!root) return true;

    queue<TreeNode*> q;
    q.push(root);

    bool hasNull = false;

    while (!q.empty()) {
        TreeNode* cur = q.front();
        q.pop();

        if (cur == nullptr) {
            hasNull = true;
        } else {
            if (hasNull) return false;
            q.push(cur->left);
            q.push(cur->right);
        }
    }

    return true;
}
  • A. 满二叉树
  • B. 完全二叉树
  • C. 二叉搜索树
  • D. 平衡二叉树
未选择
输入
输出

            
答案