我的算法的时间和空间复杂性是什么?
当我学习数据结构和算法时,我对计算算法的时间和空间的复杂性感到非常困惑。
这个问题来自 leetcode 。
def product_except_self(nums):
result = []
start = 0
while start != len(nums):
total = 1
for i in nums:
if i != nums[start]:
total *= i
result.append(total)
start += 1
return result
因此,我的计算复杂性是
时间复杂性:o(n^2)
空间复杂性:o(n)
As I am learning data structure and algorithms, I am very confused about computing the complexity of time and space of the algorithm.
This problem is from the leetcode.
def product_except_self(nums):
result = []
start = 0
while start != len(nums):
total = 1
for i in nums:
if i != nums[start]:
total *= i
result.append(total)
start += 1
return result
So, my computation complexities are,
Time Complexity: O(n^2)
Space Complexity: O(n)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你有正确的假设
Yep, you have the correct assumption