able-leopard :
Is the time complexity of python str slice O(k) or O(n)?
The answers I am reading suggest its O(k) but I don't understand how.
For example
my_str = "thisismystringfortesting"
sub_str = my_str[3:10]
I understand its extracting only (k) characters, but doesn't the operation have to convert the whole string into a list first before the slice? My thought process is that the conversion of the entire string into a list alone would cost O(n). Unless only part of the string gets converted into a list?
So can someone please explain is string slicing on Python O(k) or O(n)?
Thanks so much!
Jacques Gaudin :
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=397612&siteId=1