This for question number 260. What is the time complexity and space complexity? The array 'ans' will have only 2 elements. so space should be O(1) and time will be O(n) (n times O(1) lookup in set). Am i right?
class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
if not nums:
return [0,0]
ans=set()
for i in nums:
if i in ans:
ans.remove(i)
else:
ans.add(i)
return ans