Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Given an array of integers, arr, where all numbers occur twice except one number
- which occurs once, find the number. Your solution should ideally be O(n) time
- and use constant extra space.
- Example:
- >>> Solution().findSingle([7, 3, 5, 5, 4, 3, 4, 8, 8])
- 7
- """
- class Solution(object):
- def findSingle(self, nums):
- s = set()
- for i in nums:
- if i in s:
- s.remove(i)
- else:
- s.add(i)
- return s.pop()
- if __name__ == "__main__":
- import doctest
- doctest.testmod()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement