什么更有效率? vector.assign 对比 vector.erase

What is more efficient? vector.assign vs vector.erase

当向量存在并试图擦除该向量的背面时。 就时间复杂度而言,使用 'vector.assign' 是否有效?或者使用 'vector.erase' 是否有效?

请告诉我每种情况下的时间复杂度。

[例如]

vector<int> v = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// 1. use assign
v.assign(v.begin(), v.begin() + 5);

// 2. use erase
v.erase(v.begin() + 5, v.end());

I would like to use vectors that consist only of elements from the beginning section of vectors to a certain index.

使用 resize 效率最高,因为这就是该函数的用途。

为了它的价值,自我assignment 不允许用于容器。