# LeetCode Single Number III

Given an array of numbers 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.

For example:

Given nums = [1, 2, 1, 3, 2, 5], return [3, 5].

Note:
The order of the result is not important. So in the above example, [5, 3] is also correct.
Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?

func singleNumber(nums []int) []int {
diff := 0
for _, num := range nums {
diff = diff ^ num
}
diff = -diff & diff
result := make([]int, 2)
for _, num := range nums {
if diff & num == 0 {
result[0] = result[0] ^ num
} else {
result[1] = result[1] ^ num
}
}
return result
}
• 本文已收录于以下专栏：

## Leetcode Single Number III

class Solution { public: unsigned long intmax = 2147483647; vector singleNumber(vector& nums...

leetcode260

## LeetCode Single Number III （Java和Python代码）

• Pwiling
• 2015年10月13日 17:06
• 714

## LeetCode：Single Number I & II & III

（一）题目描述：single-number Given an array of integers, every element appears **twice** except for one. Fi...

## LeetCode（260） Single Number III

• fly_yr
• 2015年12月02日 14:41
• 1051

举报原因： 您举报文章：LeetCode Single Number III 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)