- tags: Algorithm
Bit Manipulation
Links to this note
LeetCode101: 136. Single Number
tags: Bit Manipulation,Bitwise Operator: XOR According to bitwise operator XOR: x ^ x = 0 y ^ 0 = y We apply the XOR operator to all the nums, all the same numbers will apply x ^ x = 0, and then y ^ 0 = y will result the single number. class Solution { public: int singleNumber(vector<int>& nums) { int xorN = 0; for (auto iter = nums.begin(); iter !...
Bitwise Operator: XOR
tags: Bitwise Operators 0101 (decimal 5) XOR 0011 (decimal 3) = 0110 (decimal 6) 0010 (decimal 2) XOR 1010 (decimal 10) = 1000 (decimal 8) Useful features: 1 ^ 1 = 0 2 ^ 0 = 2