Find the Element With Odd Frequency
Problem statement
Given a nonempty integer array values, exactly one distinct value occurs an odd number of times. Every other distinct value occurs an even number of times.
Return the value whose frequency is odd.
Function
findOddFrequencyElement(values: int[]) → intExamples
Example 1
values = [2,3,2,3,3]return = 3Value 2 appears twice, while 3 appears three times.
Example 2
values = [7]return = 7The only value appears once, which is odd.
Example 3
values = [10,20,10,20,10,20,10]return = 20Value 10 appears four times and 20 appears three times.
Constraints
1 <= values.length <= 200000-10^9 <= values[i] <= 10^9- Exactly one distinct value has odd frequency; every other distinct value has even frequency.