Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order.
Example 1:
Input: 
N = 2
arr[] = {1, 2, 3, 2, 1, 4}
Output:
3 4 
Explanation:
3 and 4 occur exactly once.
Example 2:
Input:
N = 1
arr[] = {2, 1, 3, 2}
Output:
1 3
Explanation:
1 3 occur exactly once.
Your Task:
You do not need to read or print anything. Your task is to complete the function singleNumber() which takes the array as input parameter and returns a list of two numbers which occur exactly once in the array. The list must be in ascending order.
Expected Time Complexity: O(N)
Expected Space Complexity: O(1)
Constraints:
1 <= length of array <= 10^{6 }
1 <= Elements in array <= 5 * 10^{6}

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Bit manipulation

Data structures

Starter code: #User function Template for python3



class Solution:

	def singleNumber(self, nums):

		# Code here



Solutions:
class Solution:

	def singleNumber(self, nums):
		temp_set = set()
		for i in range(len(nums)):
			if nums[i] in temp_set:
				temp_set.remove(nums[i])
			else:
				temp_set.add(nums[i])
		return sorted(temp_set)


class Solution:

	def singleNumber(self, nums):
		d = {}
		res = []
		for i in nums:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		for i in d:
			if d[i] == 1:
				res.append(i)
		res.sort()
		return res


class Solution:

	def singleNumber(self, nums):
		count_dict = {}
		for num in nums:
			if num in count_dict:
				count_dict[num] += 1
			else:
				count_dict[num] = 1
		result = []
		for (num, count) in count_dict.items():
			if count == 1:
				result.append(num)
		result.sort()
		return result


class Solution:

	def singleNumber(self, nums):
		xor = 0
		for i in nums:
			xor ^= i
		xor = xor & ~(xor - 1)
		a = 0
		b = 0
		for i in nums:
			if xor & i == 0:
				a ^= i
			else:
				b ^= i
		if a > b:
			return [b, a]
		return [a, b]


class Solution:

	def singleNumber(self, nums):
		nums.sort()
		c = 0
		a = []
		for h in nums:
			if c == 0:
				c ^= h
			elif c == h:
				c = 0
			else:
				a.append(c)
				c = h
		if c != 0:
			a.append(c)
		return a


class Solution:

	def singleNumber(self, nums):
		dic = {}
		for i in nums:
			if i not in dic:
				dic[i] = 1
			else:
				dic[i] += 1
		x = []
		for (key, value) in dic.items():
			if value == 1:
				x.append(key)
		return sorted(x)


class Solution:

	def singleNumber(self, nums):
		sums = 0
		for i in range(0, len(nums)):
			sums = sums ^ nums[i]
		sums = sums & -sums
		sum1 = 0
		sum2 = 0
		for i in range(0, len(nums)):
			if nums[i] & sums > 0:
				sum1 = sum1 ^ nums[i]
			else:
				sum2 = sum2 ^ nums[i]
		return sorted([sum1, sum2])


class Solution:

	def singleNumber(self, nums):
		d = {}
		for i in nums:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		l = []
		for (k, v) in d.items():
			if v == 1:
				l.append(k)
		return sorted(l)


class Solution:

	def singleNumber(self, nums):
		xor = 0
		for i in nums:
			xor ^= i
		count = 0
		n = xor
		setbit = n & ~n + 1
		num1 = xor
		num2 = xor
		for i in nums:
			if i & setbit != 0:
				num1 ^= i
			else:
				num2 ^= i
		if num1 > num2:
			return [num2, num1]
		return [num1, num2]


class Solution:

	def singleNumber(self, nums):
		xor = nums[0]
		for x in nums[1:]:
			xor = xor ^ x
		rightSetBit = xor & ~(xor - 1)
		a = 0
		b = 0
		for x in nums:
			if x & rightSetBit:
				a = a ^ x
			else:
				b = b ^ x
		if a > b:
			return [b, a]
		else:
			return [a, b]


class Solution:

	def singleNumber(self, nums):
		nl = {}
		for x in nums:
			if nl.get(x):
				nl.pop(x)
			else:
				nl[x] = 1
		result = list(nl.keys())
		if result[0] > result[1]:
			return result[::-1]
		else:
			return result


from collections import Counter

class Solution:

	def singleNumber(self, nums):
		a = []
		freq = Counter(nums)
		for (i, j) in freq.items():
			if j == 1:
				a.append(i)
		a.sort()
		return a


from collections import Counter

class Solution:

	def singleNumber(self, nums):
		ans = Counter(nums)
		l = []
		for (i, j) in ans.items():
			if j == 1:
				l.append(i)
		l.sort()
		return l


class Solution:

	def singleNumber(self, nums):
		xor = 0
		for num in nums:
			xor ^= num
		bit = 0
		while xor % 2 == 0:
			xor //= 2
			bit += 1
		group1 = []
		group2 = []
		for num in nums:
			if (num >> bit) % 2 == 0:
				group1.append(num)
			else:
				group2.append(num)
		num1 = 0
		for num in group1:
			num1 ^= num
		num2 = 0
		for num in group2:
			num2 ^= num
		return [num1, num2] if num1 < num2 else [num2, num1]


class Solution:

	def singleNumber(self, nums):
		dict = {}
		l = []
		for i in nums:
			if i in dict:
				dict[i] += 1
			else:
				dict[i] = 1
		for (number, count) in dict.items():
			if count == 1:
				l.append(number)
		l.sort()
		return l


class Solution:

	def singleNumber(self, nums):
		c = []
		d = {}
		for i in nums:
			if i in d:
				c.remove(i)
			else:
				c.append(i)
				d[i] = 1
		c.sort()
		return c


class Solution:

	def singleNumber(self, nums):
		h = {}
		ans = []
		for i in nums:
			if str(i) in h.keys():
				h[str(i)] += 1
			else:
				h.update({str(i): 1})
		for i in h.keys():
			if h[str(i)] == 1:
				ans.append(int(i))
		if len(ans) == 0:
			ans.append(-1)
		ans.sort()
		return ans


class Solution:

	def singleNumber(self, nums):
		xor = 0
		for i in nums:
			xor ^= i
		right_most_bit_pos = xor & ~(xor - 1)
		(x, y) = (0, 0)
		for i in nums:
			if i & right_most_bit_pos:
				x ^= i
			else:
				y ^= i
		return sorted([x, y])


class Solution:

	def singleNumber(self, arr):
		xorOfAllElements = arr[0]
		for i in range(1, len(arr)):
			xorOfAllElements ^= arr[i]
		rightSetBit = xorOfAllElements & ~(xorOfAllElements - 1)
		x = 0
		y = 0
		for i in range(len(arr)):
			if arr[i] & rightSetBit > 0:
				x ^= arr[i]
			else:
				y ^= arr[i]
		ans = []
		if x < y:
			ans.append(x)
			ans.append(y)
		else:
			ans.append(y)
			ans.append(x)
		return ans


class Solution:

	def singleNumber(self, nums):
		res = []
		dic = {}
		for i in nums:
			dic[i] = dic.get(i, 0) + 1
		for (i, j) in dic.items():
			if j == 1:
				res.append(i)
			if len(res) == 2:
				return sorted(res)


class Solution:

	def singleNumber(self, nums):
		x = 0
		list1 = []
		for i in range(len(nums)):
			x = x ^ nums[i]
		right = x & -x
		x = y = 0
		for i in range(len(nums)):
			if right & nums[i]:
				x = x ^ nums[i]
			else:
				y = y ^ nums[i]
		list1.append(x)
		list1.append(y)
		return sorted(list1)


from collections import *
from math import *
from sys import *
from os import *

class Solution:

	def singleNumber(self, nums):
		list1 = []
		xor = 0
		for i in range(len(nums)):
			xor = xor ^ nums[i]
		x = y = 0
		right = xor & -xor
		for i in range(len(nums)):
			if right & nums[i]:
				x = x ^ nums[i]
			else:
				y = y ^ nums[i]
		list1.append(x)
		list1.append(y)
		return sorted(list1)


from collections import *
from math import *
from sys import *
from os import *

class Solution:

	def singleNumber(self, nums):

		def UniqueNumbers2(arr, n):
			sums = 0
			for i in range(0, n):
				sums = sums ^ arr[i]
			sums = sums & -sums
			sum1 = 0
			sum2 = 0
			list1 = []
			for i in range(0, len(arr)):
				if arr[i] & sums > 0:
					sum1 = sum1 ^ arr[i]
				else:
					sum2 = sum2 ^ arr[i]
			list1.append(sum1)
			list1.append(sum2)
			return sorted(list1)
		return UniqueNumbers2(nums, len(nums))


from collections import *
from math import *
from sys import *
from os import *

class Solution:

	def singleNumber(self, nums):
		list1 = []
		dic = Counter(nums)
		for (key, value) in dic.items():
			if value == 1:
				list1.append(key)
		return sorted(list1)


from collections import *

class Solution:

	def singleNumber(self, nums):
		dic = Counter(nums)
		list1 = []
		for (freq, n) in dic.items():
			if n == 1:
				list1.append(freq)
		if list1[0] > list1[1]:
			(list1[0], list1[1]) = (list1[1], list1[0])
		return list1


class Solution:

	def singleNumber(self, nums):
		res = []
		d = {}
		for i in nums:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for i in d:
			if d[i] == 1:
				res.append(i)
		return sorted(res)


class Solution:

	def singleNumber(self, nums):
		ans = []
		counts = {}
		for i in nums:
			if i in counts:
				counts[i] += 1
			else:
				counts[i] = 1
		for (num, count) in counts.items():
			if count == 1:
				ans.append(num)
		ans.sort()
		return ans


class Solution:

	def singleNumber(self, nums):
		sum = 0
		for i in range(len(nums)):
			sum = sum ^ nums[i]
		right = sum & ~(sum - 1)
		(x, y) = (0, 0)
		for i in range(len(nums)):
			if nums[i] & right > 0:
				x = x ^ nums[i]
			else:
				y = y ^ nums[i]
		ans = []
		ans.append(x)
		ans.append(y)
		return sorted(ans)


from collections import Counter

class Solution:

	def singleNumber(self, nums):
		s = []
		x = Counter(nums)
		for i in x:
			if x[i] == 1:
				s.append(i)
		s.sort()
		return s


class Solution:

	def singleNumber(self, nums):
		ans = 0
		for i in nums:
			ans ^= i
		ans = ans & ~(ans - 1)
		(set1, set2) = (0, 0)
		for i in nums:
			if i & ans:
				set1 ^= i
			else:
				set2 ^= i
		res = []
		if set1 > set2:
			res.extend([set2, set1])
		else:
			res.extend([set1, set2])
		return res


class Solution:

	def singleNumber(self, nums):
		ans = {}
		a = []
		for i in nums:
			if i not in ans:
				ans[i] = 1
			else:
				ans[i] += 1
		for i in ans:
			if ans[i] == 1:
				a.append(i)
		a.sort()
		return a


class Solution:

	def singleNumber(self, nums):
		check_dup = {}
		for ele in nums:
			if ele in check_dup:
				check_dup[ele] += 1
			else:
				check_dup[ele] = 1
		res = []
		for ele in nums:
			if check_dup[ele] == 1:
				res.append(ele)
		return sorted(res)


class Solution:

	def singleNumber(self, nums):
		sums = 0
		for i in range(len(nums)):
			sums = sums ^ nums[i]
		sums = sums & -sums
		sum1 = 0
		sum2 = 0
		for i in range(len(nums)):
			if sums & nums[i] > 0:
				sum1 = sum1 ^ nums[i]
			else:
				sum2 = sum2 ^ nums[i]
		lis = []
		lis.append(sum1)
		lis.append(sum2)
		lis.sort()
		return lis


class Solution:

	def singleNumber(self, s):
		freq = {}
		for ch in s:
			freq[ch] = freq.get(ch, 0) + 1
		unique_chars = [ch for ch in freq if freq[ch] == 1]
		return sorted(unique_chars)


class Solution:

	def singleNumber(self, nums):
		l = {}
		li = []
		for i in nums:
			if i in l:
				l[i] += 1
			else:
				l[i] = 1
		for key in l:
			if l[key] == 1:
				li.append(key)
		return sorted(li)


import math

class Solution:

	def singleNumber(self, nums):
		d = dict()
		l = list()
		for n in nums:
			if n in d:
				d[n] += 1
			else:
				d[n] = 1
		for key in d:
			if d[key] == 1:
				l.append(key)
		l.sort()
		return l


class Solution:

	def singleNumber(self, nums):
		nums.sort(reverse=True)
		res = []
		while nums:
			if len(nums) == 1:
				res.append(nums[0])
				break
			curr1 = nums.pop()
			curr2 = nums.pop()
			if curr1 != curr2:
				res.append(curr1)
				nums.append(curr2)
			if len(res) == 2:
				break
		return res


class Solution:

	def singleNumber(self, nums):
		summ = 0
		for i in nums:
			summ = summ ^ i
		summ = summ & -summ
		a = 0
		b = 0
		for i in nums:
			if i & summ > 0:
				a = a ^ i
			else:
				b = b ^ i
		if a > b:
			return [b, a]
		else:
			return [a, b]


class Solution:

	def singleNumber(self, nums):
		xor = 0
		for n in nums:
			xor ^= n
		x = 0
		y = 0
		rmsb = xor & ~(xor - 1)
		for n in nums:
			if n & rmsb == rmsb:
				x ^= n
			else:
				y ^= n
		return sorted([x, y])


class Solution:

	def singleNumber(self, nums):
		hash = {}
		res = []
		for n in nums:
			if hash.get(n, None) == None:
				hash[n] = 1
			else:
				hash[n] += 1
		for (key, value) in hash.items():
			if value == 1:
				res.append(key)
		if res[0] > res[1]:
			(res[0], res[1]) = (res[1], res[0])
		return res


class Solution:

	def singleNumber(self, nums):
		res = []
		for n in nums:
			if n in res:
				res.remove(n)
			else:
				res.append(n)
		res.sort()
		return res


import collections
from collections import defaultdict

class Solution:

	def singleNumber(self, nums):
		map = {}
		ans = []
		n = len(nums)
		for i in range(n):
			if nums[i] in map:
				map[nums[i]] += 1
			else:
				map[nums[i]] = 1
		for i in map:
			if map[i] == 1:
				ans.append(i)
		ans.sort()
		return ans


import collections
from collections import defaultdict

class Solution:

	def singleNumber(self, nums):
		ans = []
		xor = 0
		n = len(nums)
		for i in range(n):
			xor = xor ^ nums[i]
		right_bit = xor & ~(xor - 1)
		x = 0
		y = 0
		for i in range(n):
			if nums[i] & right_bit:
				x = x ^ nums[i]
			else:
				y = y ^ nums[i]
		ans.append(x)
		ans.append(y)
		ans.sort()
		return ans


class Solution:

	def singleNumber(self, nums):
		f = {}
		for i in nums:
			if i in f:
				f[i] += 1
			else:
				f[i] = 1
		l = []
		for i in nums:
			if f[i] == 1:
				l.append(i)
		l.sort()
		return l


class Solution:

	def singleNumber(self, arr):
		l = []
		d = {}
		for x in arr:
			if x in d:
				d[x] = d[x] + 1
			else:
				d[x] = 1
		for x in arr:
			if d[x] < 2:
				l.append(x)
		l.sort()
		return l


from collections import Counter

class Solution:

	def singleNumber(self, nums):
		d = Counter(nums)
		l = []
		for (k, v) in d.items():
			if v == 1:
				l.append(k)
		return sorted(l)


class Solution:

	def singleNumber(self, nums):
		dictionary = {}
		for i in nums:
			if i not in dictionary:
				dictionary[i] = 1
			else:
				dictionary[i] += 1
		a = []
		for (b, c) in dictionary.items():
			if c == 1:
				a.append(b)
		return sorted(a)


class Solution:

	def singleNumber(self, nums):
		nums.sort()
		output = []
		i = 0
		while i < len(nums):
			if i == len(nums) - 1:
				output = output + [nums[i]]
				break
			if nums[i] != nums[i + 1]:
				output = output + [nums[i]]
				i = i + 1
			else:
				i = i + 2
		return output


class Solution:

	def singleNumber(self, nums):
		xor = 0
		for i in nums:
			xor = i ^ xor
		listt1 = []
		listt2 = []
		num = 0
		a = xor
		while xor > 0:
			if xor % 2 == 1:
				break
			else:
				num += 1
				xor //= 2
		xor1 = 0
		for i in nums:
			if i // 2 ** num % 2 == 0:
				xor1 = xor1 ^ i
		return (min(xor1, xor1 ^ a), max(xor1, a ^ xor1))


class Solution:

	def singleNumber(self, nums):
		nums.sort()
		count = 0
		ini = nums[0]
		listt = []
		for i in nums:
			if i == ini:
				count += 1
			else:
				if count % 2 == 1:
					listt.append(ini)
				ini = i
				count = 1
		if count % 2 == 1:
			listt.append(ini)
		return (listt[0], listt[1])


class Solution:

	def ithBitSet(self, n: int, i: int) -> bool:
		return n & 1 << i != 0

	def singleNumber(self, nums):
		xor = 0
		for num in nums:
			xor ^= num
		i = 0
		while xor & 1 == 0:
			xor = xor >> 1
			i += 1
		res1 = 0
		res2 = 0
		for num in nums:
			if self.ithBitSet(num, i):
				res1 ^= num
			else:
				res2 ^= num
		return sorted([res1, res2])


class Solution:

	def singleNumber(self, nums):
		val = nums[0]
		for i in range(1, len(nums)):
			val = val ^ nums[i]
		rsb = val & -val
		num1 = 0
		num2 = 0
		for i in nums:
			if i & rsb == 0:
				num1 = num1 ^ i
			else:
				num2 = num2 ^ i
		return [min(num1, num2), max(num1, num2)]


class Solution:

	def singleNumber(self, arr):
		res = 0
		for elm in arr:
			res ^= elm
		res = bin(res)[2:]
		pos = -1
		for i in range(-1, -len(res) - 1, -1):
			if res[i] == '1':
				pos = i
				break
		res = int(res, 2)
		new = res
		for elm in arr:
			if -len(bin(elm)[2:]) <= pos and bin(elm)[2:][pos] == '1':
				res ^= elm
		ans = [res]
		ans.append(res ^ new)
		ans.sort()
		return ans


class Solution:

	def singleNumber(self, nums):
		res = 0
		for num in nums:
			res = res ^ num
		bRes = bin(res)[2:]
		pos = -1
		for i in range(len(bRes) - 1, -1, -1):
			if bRes[i] == '0':
				pos -= 1
			else:
				break
		temp1 = res
		temp2 = res
		for num in nums:
			bNum = bin(num)[2:]
			if pos >= -1 * len(bNum) and bNum[pos] == '1':
				temp1 = temp1 ^ num
			else:
				temp2 = temp2 ^ num
		a = [temp1, temp2]
		a.sort()
		return a
		return [3, 4]


class Solution:

	def singleNumber(self, nums):
		xr = 0
		for i in nums:
			xr ^= i
		a = []
		b = []
		i = 0
		while 1:
			if xr & 1 << i:
				break
			i += 1
		v = 1 << i
		for i in nums:
			if v & i:
				a.append(i)
			else:
				b.append(i)
		xa = 0
		xb = 0
		for i in a:
			xa ^= i
		for i in b:
			xb ^= i
		if xa < xb:
			return [xa, xb]
		return [xb, xa]


class Solution:

	def singleNumber(self, nums):
		dic = {}
		crr = []
		for i in nums:
			if i not in dic:
				dic[i] = 1
			else:
				dic[i] += 1
		for l in dic:
			if dic[l] == 1:
				crr.append(l)
		crr.sort()
		return crr


class Solution:

	def singleNumber(self, nums):
		d = {}
		l = []
		for i in nums:
			try:
				d[i] += 1
				l.remove(i)
			except:
				d[i] = 1
				l.append(i)
		return sorted(l)


from collections import Counter

class Solution:

	def singleNumber(self, nums):
		list1 = list()
		nums = Counter(nums)
		for (i, j) in nums.items():
			if j == 1:
				list1.append(i)
		list1.sort()
		return list1


from collections import Counter

class Solution:

	def singleNumber(self, nums):
		L = []
		c = Counter(nums)
		for i in c:
			if c[i] == 1:
				L.append(i)
		L.sort()
		return L


class Solution:

	def singleNumber(self, nums):
		res = 0
		for i in nums:
			res = res ^ i
		setbit = 0
		setbit = res & ~(res - 1)
		res1 = 0
		res2 = 0
		for i in nums:
			if i & setbit:
				res1 = res1 ^ i
			else:
				res2 = res2 ^ i
		x = min(res1, res2)
		y = max(res1, res2)
		return (x, y)


class Solution:

	def singleNumber(self, nums):
		hash_map = {}
		for i in nums:
			if i not in hash_map:
				hash_map[i] = 1
			else:
				hash_map.pop(i)
		ans = []
		for key in hash_map:
			ans.append(key)
		ans.sort()
		return ans


class Solution:

	def singleNumber(self, nums):
		table = {}
		for i in nums:
			if i in table:
				table[i] += 1
			else:
				table[i] = 1
		arr = []
		for j in table:
			if table[j] == 1:
				arr.append(j)
		arr.sort()
		return arr


class Solution:

	def singleNumber(self, a):
		d = {}
		for i in a:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		ans = []
		for i in d:
			if d[i] < 2:
				ans.append(i)
		return sorted(ans)


class Solution:

	def singleNumber(self, nums):
		single = []
		dict = {}
		for i in nums:
			if i in dict:
				dict[i] += 1
			else:
				dict[i] = 1
		for i in dict:
			if dict[i] == 1:
				single.append(i)
		single.sort()
		return single


class Solution:

	def singleNumber(self, nums):
		hmap = {}
		for i in range(len(nums)):
			if nums[i] in hmap:
				hmap[nums[i]] += 1
			else:
				hmap[nums[i]] = 1
		result = []
		for item in nums:
			if hmap[item] == 1:
				result.append(item)
		result = sorted(result)
		return result


class Solution:

	def singleNumber(self, n):
		m = 0
		for i in n:
			m = m ^ i
		i = 0
		while m > 0:
			if m & 1 == 1:
				break
			m = m >> 1
			i = i + 1
		l = []
		r = []
		for j in n:
			if j & 1 << i:
				l.append(j)
			else:
				r.append(j)
		s = []
		x = 0
		y = 0
		for i in l:
			x = x ^ i
		s.append(x)
		for i in r:
			y = y ^ i
		s.append(y)
		s.sort()
		return s


class Solution:

	def singleNumber(self, nums):
		sum_ = 0
		for num in nums:
			sum_ ^= num
		sum_ = sum_ & -sum_
		sum1 = sum2 = 0
		for num in nums:
			if num & sum_:
				sum1 ^= num
			else:
				sum2 ^= num
		if sum1 < sum2:
			return [sum1, sum2]
		return [sum2, sum1]


class Solution:

	def singleNumber(self, nums):
		xor = 0
		for n in nums:
			xor ^= n
		rsb = xor & -xor
		(ans1, ans2) = (0, 0)
		for n in nums:
			if rsb & n:
				ans1 ^= n
			else:
				ans2 ^= n
		return sorted([ans1, ans2])


class Solution:

	def singleNumber(self, nums):
		d = {}
		for ele in nums:
			if ele not in d:
				d[ele] = 1
			else:
				d[ele] += 1
		ele = []
		for e in d:
			if d[e] == 1:
				ele.append(e)
		ele.sort()
		return ele


class Solution:

	def singleNumber(self, nums):
		a = []
		all_freq = {}
		for i in nums:
			if i in all_freq:
				all_freq[i] += 1
			else:
				all_freq[i] = 1
		for (key, value) in all_freq.items():
			if value == 1:
				a.append(key)
		a.sort()
		return a


class Solution:

	def singleNumber(self, nums):
		if len(nums) == 0:
			return
		if 1 > len(nums) > 10 ** 6:
			return
		final = []
		nums_set = list(set(nums))
		for i in nums_set:
			if 1 <= i <= 50 * 10 ** 6 and nums.count(i) == 1:
				final.append(i)
				if len(final) == 2:
					break
		final.sort()
		return final


class Solution:

	def singleNumber(self, nums):
		xor = nums[0]
		for i in nums[1:]:
			xor = xor ^ i
		ans = []
		right_bit = xor & ~(xor - 1)
		x = 0
		y = 0
		for i in range(len(nums)):
			if nums[i] & right_bit:
				x = x ^ nums[i]
			else:
				y = y ^ nums[i]
		ans.append(x)
		ans.append(y)
		ans.sort()
		return ans


class Solution:

	def singleNumber(self, nums):
		bitmask = 0
		for num in nums:
			bitmask ^= num
		diff = bitmask & -bitmask
		x = 0
		for num in nums:
			if num & diff:
				x ^= num
		y = bitmask ^ x
		return [x, y] if x < y else [y, x]


class Solution:

	def singleNumber(self, nums):
		from collections import Counter
		res = Counter(nums)
		sol = []
		for i in res:
			if res[i] == 1:
				sol.append(i)
		sol.sort()
		return sol


class Solution:

	def singleNumber(self, nums):
		d = dict()
		for i in nums:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		c = []
		for i in d:
			if d[i] == 1:
				c.append(i)
		if c[0] > c[1]:
			(c[0], c[1]) = (c[1], c[0])
		return c


import collections
from collections import defaultdict

class Solution:

	def singleNumber(self, nums):
		d = defaultdict(list)
		for i in nums:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		ans = []
		for (k, v) in d.items():
			if v == 1:
				ans.append(k)
		return sorted(ans)