我得到了以下代碼,并被告知 func 函數的 Big O 是 Big O (n^2)。我相信它是大 O(n),因為它應該是大 O(n + n),我錯了嗎?what is Big O of following func?nums = list(range(1, 11))K = 4def func(nums: list, K:int): i, end = 0, len(nums) res = [] x = [] while i < end: res.append(nums[i:i+K]) i += K for i in res: x += i[::-1] return xfunc(nums, K)
如何使用 while + for 循環計算 Big O
慕田峪9158850
2021-12-29 10:25:42
