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

标签 c++ string big-o

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

相关文章:

c++ - 如何为静态模板方法起别名?

Python - 在文本文件中搜索字符串

c - 从 C 中的结构返回 char 数组时出现奇怪的字符

algorithm - 为什么 Induction 总是不适用于 Big-O?

string - 特殊交织字符串编码

algorithm - 确定大 O 符号

c++ - OpenCV - 缺少调试 DLL 库

c++ - Visual C++ 项目找不到外部依赖项的 'xyz.h' 文件

c++ - Qt 框架 : How to display a QGraphicsView in a layout?

string - bash 中的子字符串替换