修改 std::string 的运行时间是多少?我假设时间恒定,或者在字符串类的幕后发生了更多事情?
#include <string>
int main() {
std::string str = "Hello World!"
str[1] = 'a'; // <--- what is the runtime?
}
干杯
最佳答案
没错,它是恒定的。根据this :
Complexity
Constant.
对于 C++11,也就是说,它没有为 C++98 指定,但我不认为使用非常量 std::string::operator[]
的实现会是司空见惯。
关于c++ - 在 C++ 中修改字符串的 BigO 时间复杂度是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58764361/