Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Difficulty:Medium
class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
leng = len(nums)
i = 0
nums.sort()
while i<leng:
if(i+2>=leng):
return nums[i]
elif(nums[i]!=nums[i+2]):
return nums[i]
else:
i+=3