classSolution { funsingleNumbers(nums: IntArray): IntArray { var xorOf2 = 0 val ans = IntArray(2) val flag = BooleanArray(2) var difDigit = 0 flag[0] = false for (num in nums) { xorOf2 = if (flag[0]) xorOf2 xor num else num flag[0] = true } for (i in0..31) { if (xorOf2 and (1 shl i) != 0) { difDigit = i break } } flag[0] = false for (num in nums) { if (num and (1 shl difDigit) == 0) { ans[0] = if (flag[0]) ans[0] xor num else num flag[0] = true } if (num and (1 shl difDigit) != 0) { ans[1] = if (flag[1]) ans[1] xor num else num flag[1] = true } } return ans } }