What is the complexity of std::string::substr member function?

前端 未结 3 765
悲&欢浪女
悲&欢浪女 2020-12-18 07:37

What is the complexity of std::string::substr member function? Is it defined by standard or implementation-defined?

3条回答
  •  独厮守ぢ
    2020-12-18 07:42

    A naïve implementation would be O(k) where k is the length of the resulting substring. std::string does not support copy-on-write. If you want O(1) substring operations, use a data structure such as a Rope.

提交回复
热议问题