思路:异或运算
a^0=a
a^a=0
a ^ b ^ c = a ^ c ^ b
class Solution {
public int singleNumber(int[] nums) {
int single = 0;
for (int num : nums) {
single ^= num;
}
return single;
}
}
思路:异或运算
a^0=a
a^a=0
a ^ b ^ c = a ^ c ^ b
class Solution {
public int singleNumber(int[] nums) {
int single = 0;
for (int num : nums) {
single ^= num;
}
return single;
}
}