Guest User

Untitled

a guest
Oct 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. """
  2. Description:
  3. Given a non-empty array of integers, every element appears twice except for one. Find
  4. that single one. The algorithm should have a linear runtime complexity.
  5.  
  6. Examples:
  7. Input: [2,2,1]
  8. Output: 1
  9.  
  10. Input: [4,1,2,1,2]
  11. Output: 4
  12. """
  13.  
  14. def singleNumber(nums):
  15. """
  16. :type nums: List[int]
  17. :rtype: int
  18. """
  19. v = 0
  20. for num in nums:
  21. v ^= num
  22. return v
Add Comment
Please, Sign In to add comment