Subject description:
Chinese:
Given a non-empty array of integers, in addition to an element appears only once, the rest of each element appears twice. To find out that only appears once in the elements.
Description:
Your algorithm should have linear time complexity. You can not use the extra space to achieve it?
English:
Given a non-empty 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 """ return 2*sum(set(nums)) - sum(nums)
Topic Source: stay button