As this is one question in a series of questions. I am modifying this to make it not duplicate from other ones. Thanks for all the help.
Pairs: I have an array of integers. In the array, every element appears twice except for one. I want to find that single number.
Example: [2, 4, 2, 1, 4, 1, 3]
, single number is 3
.
My thought is to use a HashMap
, which takes O(n)
time and O(n)
space. Are there any better solutions? Thanks.
Triples: every element appears three times except for one. Find that single one.
Example: [1, 2, 4, 2, 4, 1, 2, 4, 1, 3]
, single number is 3
.