Two Single Numbers (medium)
Problem Statement
In a non-empty array of numbers, every number appears exactly twice except two numbers that appear only once. Find the two numbers that appear only once.
Example 1:
Input: [1, 4, 2, 1, 3, 5, 6, 2, 3, 5]
Output: [4, 6]
Example 2:
Input: [2, 1, 3, 2]
Output: [1, 3]
Try it yourself
Try solving this question here:
class TwoSingleNumbers {public static int[] findSingleNumbers(int[] nums) {// TODO: Write your code herereturn new int[] { -1, -1 };}public static void main(String[] args) {int[] arr = new int[] { 1, 4, 2, 1, 3, 5, 6, 2, 3, 5 };int[] result = TwoSingleNumbers.findSingleNumbers(arr);System.out.println("Single numbers are: " + result[0] + ", " + result[1]);arr = new int[] { 2, 1, 3, 2 };result = TwoSingleNumbers.findSingleNumbers(arr);System.out.println("Single numbers are: " + result[0] + ", " + result[1]);}}
Solution
This problem is quite similar to Single Number, the only difference is that, in this problem, we have ...