Python 的 collections.Counter.total() 的时间复杂度是多少?
What's the time complexity of Python's collections.Counter.total()?
Python 的 collections.Counter.total() 的时间复杂度是多少?我已经阅读了 method 的文档,但没有提到它的效率。有谁知道这个方法是如何在幕后实现的,它的时间复杂度是多少?
在 CPython 中,它看起来像是使用 sum(self.values())
实现 total()
,所以它是 O(number of values in the Counter)
。
Python 的 collections.Counter.total() 的时间复杂度是多少?我已经阅读了 method 的文档,但没有提到它的效率。有谁知道这个方法是如何在幕后实现的,它的时间复杂度是多少?
在 CPython 中,它看起来像是使用 sum(self.values())
实现 total()
,所以它是 O(number of values in the Counter)
。