Ama*_*eur 3 complexity-theory for-loop if-statement
I am wondering if in a situation like the following (an if/else statement under a for loop) the complexity would be O(n) or O(n^2):
for character in string:
if character==something:
do something
else:
do something else.
Run Code Online (Sandbox Code Playgroud)
Thank you!
小智 5
这将是
如果“做某事”和“做某事”为O(1),则为O(n)
如果“做某事”和“做某事”为O(n),则为O(n ^ 2)
基本上,for循环的复杂度取决于it组件和no的复杂度。的循环。