title: XOR Operation Intuition
body: <p>I recently came across <a href="https://leetcode.com/problems/single-number/">this</a> question on Leetcode and figured out a solution that I need some clarification with:</p>
  
  <blockquote>
    <p>Given an array of integers, every element appears twice except for one. Find that single one.</p>
    
    <p>Note:
    Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?</p>
  </blockquote>
  
  <pre><code>class Solution {
  public:
      int singleNumber(vector&lt;int&gt;&amp; nums) {
          int result = 0;
          for(auto &amp; c : nums) {
              result ^= c;
          }
          return result;
      }
  };
  </code></pre>
  
  <p>First of all, what sorts of keywords should I be paying attention to in order to figure out that I should be using an XOR operation for this question?</p>
  
  <p>Also, why does XOR'ing all items in the vector with each other give us the one that is not repeated?</p>
  
  <hr>
  
  <p>Thank you all for these responses, here is some more information on bitwise properties for anyone else interested: <a href="http://www.geeksforgeeks.org/interesting-facts-bitwise-operators-c/">More bitwise info</a></p>