利用异或性质解答。
class Solution { public: int singleNumber(vector<int>& nums) { //异或自反性 A XOR B XOR B = A xor 0 = A int res = 0; for (int num : nums) res ^= num; return res; } };
利用异或性质解答。
class Solution { public: int singleNumber(vector<int>& nums) { //异或自反性 A XOR B XOR B = A xor 0 = A int res = 0; for (int num : nums) res ^= num; return res; } };