I am trying to find a Single Duplicate element in an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. As its only single element so i did like this.
def findDuplicate(self, nums: [int]) ->:
res1=0
res2=0
for i in range(1,len(nums)+1):
res1^=i
for i in range(0,len(nums)):
res2^=nums[i]
print(res1^res2)
I am using the input as [1,2,3,3,4] Instead of printing 3 its giving output as 6.