Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.
You must write an algorithm that runs in linear runtime complexity and uses only constant extra space.
Explanation: [5, 3] is also a valid answer.
nums will appear twice, only two integers will appear once.The simplest approach to solve this problem is to use a HashMap to count the occurrences of each number in the array. We then find the two numbers that appear exactly once by iterating through the map.
A more optimal solution uses bit manipulation. First, XOR all numbers to find the XOR of the two unique numbers. Then, find a bit that is set (1) in the XOR result and use it to differentiate the two unique numbers.