Find the Value That Appears Once
Problem statement
You are given an integer array nums that holds exactly two different values. One value appears exactly once. The other value fills every other position.
Return the value that appears exactly once.
Function
findSingle(nums: int[]) → intExamples
Example 1
nums = [1,2,2,2,2]return = 1The value 2 appears four times and 1 appears once. The answer is 1.
Example 2
nums = [3,3,3,3,4]return = 4The value 3 appears four times and 4 appears once, at the end. The answer is 4.
Example 3
nums = [2,2,3,2,2,2]return = 3The value 2 appears five times and 3 appears once, in the middle. The answer is 3.
Constraints
3 <= nums.length <= 5 * 10^4-10^9 <= nums[i] <= 10^9numsholds exactly two different values, and one of them appears exactly once.