我解决一个问题在本文给出了找到O(1)的空间和O(n)的时间
鉴于包含n + 1点的整数,其中每个整数是1和n之间的阵列NUMS(包括重复的数),证明至少有一个重复号码必须存在。假设只存在一个重复的号码,找到重复一个在O(n)的时间和O(1)空间复杂度
class Solution(object):
def findDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
xor=0
for num in nums:
newx=xor^(2**num)
if newx<xor:
return num
else:
xor=newx
我得到了解决办法接受,但有人告诉我,这既不是O(1 )空间也不O(n)时间。
任何人都可以请帮我理解为什么?
这可能是[在O(n)和恒定空间中查找重复](https://stackoverflow.com/questions/9072600/find-repeating-in-on-and-constant-space)和/或[如何找到算法的时间复杂度](https://stackoverflow.com/questions/11032015/how-to-find-time-complexity-of-an-algorithm)或[时间复杂度的权力()]( https://stackoverflow.com/questions/5231096/time-complexity-of-power) – Dukeling