#3849. [GESP202512 六级 C++] 第 6 题

[GESP202512 六级 C++] 第 6 题

以下函数 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) {
            hasNull = true;
        } else {
            if (hasNull) return false;
            q.push(cur->left);
            q.push(cur->right);
        }
    }
    return true;
}

{{ select(1) }}

  • 满二叉树
  • 完全二叉树
  • 二叉搜索树
  • 平衡二叉树