How to get the number which repeated the fewest times ?
For example:
- from [1,2,3,4,5,6,6,2,3,4,6] return [1] because “1” is only repeated onces while others are repeated 2 or more times.
- from [1,1,1,2,3,3,4,4,5,6,6,2,3,4] return [2,6] because both “2” and “6” are only repeated twice instead of three or more times for other numbers.
This should work:
Update: O(n) time
Here are benchmarks(running this test 10,000 times) between the first and second method:
with an array set to: