Find the Unpaired Numbers
Problem statement
In the array nums, almost every value has a partner: it appears exactly twice. Exactly k values have no partner and appear only once, where k is 1 or 2.
Return the k unpaired values in increasing order.
Try to use only a constant amount of extra memory besides the input.
Function
unpairedNumbers(nums: int[], k: int) → int[]Examples
Example 1
nums = [7,3,5,3,7]k = 1return = [5]3 and 7 each appear twice; 5 appears once.
Example 2
nums = [4,-6,9,4,2,9]k = 2return = [-6,2]4 and 9 appear twice. The two values that appear once are -6 and 2, returned in increasing order.
Example 3
nums = [0]k = 1return = [0]A single value is unpaired.
Constraints
kis1or2nums.length == 2 * m + kfor some0 <= m <= 1000-10^9 <= nums[i] <= 10^9- Exactly
kvalues appear once innums, and every other value appears exactly twice.