Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
s = set(nums)
l = list(s)
str1 = str(nums)
for x in l:
if str1.count(str(x)) == 1:
return x
class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
a = len(nums)
if a == 1:
return nums[0]
sum = 0
for x in nums:
sum = sum ^ x
return sum