Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Description:
- Given a non-empty array of integers, every element appears twice except for one. Find
- that single one. The algorithm should have a linear runtime complexity.
- Examples:
- Input: [2,2,1]
- Output: 1
- Input: [4,1,2,1,2]
- Output: 4
- """
- def singleNumber(nums):
- """
- :type nums: List[int]
- :rtype: int
- """
- v = 0
- for num in nums:
- v ^= num
- return v
Add Comment
Please, Sign In to add comment