简体   繁体   English

访问collections.deque长度的时间复杂度

[英]Time complexity of accessing collections.deque length

What is the time complexity of calling Python's built-in len() function on collections.deque ? collections.deque上调用Python的内置len()函数的时间复杂度是多少? I expect it to be O(1), but I haven't found any confirmation of this fact. 我希望它是O(1),但我没有找到任何关于这一事实的确认。

In CPython time complexity is O(1) indeed. 在CPython中,时间复杂度确实是O(1)。 This fact can be deduced by looking at the source code of CPython (look at chepner's comment ). 这个事实可以通过查看CPython的源代码来推断(查看chepner的评论 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM