Leetcode: Number of bachelors found
Question:
Given an array of integers, every element appears twice should t for one. Find that single one.
Note:
Your algorithm shocould have a linear runtime complexity. cocould you implement it without using extra memory?
Ideas:
I have heard of this question. The bitwise operator may think of two equal numbers for an exclusive or operation and the result is zero, zero and any non-zero number exclusive or the operation result is the non-zero number itself. Based on this, all elements in the array are connected in series for an exclusive or, those pairing changes to zero, and the final order must be different from zero, and the result must be its own. It doesn't matter if the order of XOR is normal? It doesn't matter. Exclusive or operations have a combination of laws and do not care about order, so you don't need to care about this detail.
Code:
Class Solution {public: int singleNumber (int A [], int n) {int re; for (int I = 0; I