각 정수는 1과 N 사이에 여기서 n + 1의 정수를 포함O (1) 공간과 O (n)을 포함하는 시간
을 감안할 때 배열 nums (와 중복 번호를 찾을 수), 적어도 하나의 중복 된 숫자가 존재해야 함을 증명하십시오. (1, 단 하나의 중복 된 숫자가 있다고 가정 내가 솔루션 허용 얻었다 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이라고 들었습니다) 공간 또는 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