Py学习  »  Python

Python字符串迭代的时间复杂性

Learning stats by example • 5 年前 • 1866 次点击  

Python的时间复杂度是多少? for in 带字符串的迭代构造?

例如。,

for s in 'test:
   ... # s = t, e, s, t

循环的总运行时间是多少?

编辑:我看到我混淆了Python的字符串片段查找和索引查找。它的索引查找是O(1),因此总循环应该是O(n),与列表相同。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52709
 
1866 次点击  
文章 [ 2 ]  |  最新文章 5 年前