简体   繁体   English

字符串重复的时间复杂度(通过 str * int)

[英]Time complexity of string repetition (via str * int)

What's the time complexity of repeating a string in python with the String * int operator?使用 String * int 运算符在 python 中重复字符串的时间复杂度是多少?

To be clear, I'm talking about this phenomenon:为了清楚起见,我说的是这种现象:

print("a"*4)

would output "aaaa"将 output “aaaa”

I tried to find an answer myself, but can't find anything about this, and it's worse because I am unsure of what it's called... I'm just calling it string repetition for now.我试图自己找到答案,但找不到任何关于这个的东西,而且更糟糕的是因为我不确定它叫什么......我现在只是称之为字符串重复。

According to this lecture , given an integer k and a list l , k*l is of complexity O(k*N) .根据这个讲座,给定一个 integer k和一个列表lk*l的复杂度为O(k*N)

Since strings are iterables too, I assume the answer is the same for strings.由于字符串也是可迭代的,我假设字符串的答案是相同的。

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

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