gpt4 book ai didi

c++ - 在 C++ 中修改字符串的 BigO 时间复杂度是多少?

转载 作者:行者123 更新时间:2023-11-30 03:13:19 26 4
gpt4 key购买 nike

修改 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com