-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
@Geekhyt
Description
位运算
- 一个数和 0 做异或运算等于其本身
- 一个数和它本身做异或运算等于 0
- 异或运算满足交换律和结合律
数组中所有元素的异或运算结果就是数组中只出现一次的数字。
const singleNumber = function(nums) { let ans = 0 for (const num of nums) { ans ^= num } return ans }
- 时间复杂度:O(n)
- 空间复杂度:O(1)