第20995题
给定C++实现的树的广度优先遍历代码,其时间复杂度为多少?
void bfs(TreeNode* root) {
    if (!root) return;
    queue<TreeNode*> q;
    q.push(root);
    while (!q.empty()) {
        TreeNode* node = q.front();
        q.pop();
        cout << node->val << " ";
        if (node->left) q.push(node->left);
        if (node->right) q.push(node->right);
    }
}
A

O(n)

B

O(log n)

C

O(n²)

D

O(2ⁿ)