Недавно я начал изучать структуры данных на Python
Код: Выделить всё
list_ = [6, 4, 3, 2, 1, 7]
expected_sum_result = 9
def two_pair_sum_using_complement(array, expected_sum):
unique_numbers = set() #set
for num in array:
if num in unique_numbers:
return True
unique_numbers.add(expected_sum - num)
print(unique_numbers)
return False
print(
two_pair_sum_using_complement(array=list_, expected_sum=expected_sum_result))
So, May I consider I have a FOR loop that is O(n) and I have an in operator that has O(n) inside the FOR loop, so the complexity is O(n^2)?
I've tried by using some websites and AI and I can't understand the things easily.
Источник: https://stackoverflow.com/questions/781 ... complexity