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

修改std :: string的运行时是什么?我假设时间是固定的,还是在字符串类的后台进行了很多事情?

#include <string>

int main() {
  std::string str = "Hello World!"
  str[1] =  'a';  // <--- what is the runtime?
}

欢呼

zhufu0802114 回答:在C ++中修改字符串的BigO时间复杂度是多少?

是的,它是恒定的。根据{{​​3}}:

  

复杂度

     

恒定。

对于C ++ 11而言,对于C ++ 98尚未指定,但我不认为使用非常数std::string::operator[]的实现会很常见。

本文链接:https://www.f2er.com/3138853.html

大家都在问