title: Single Number II from leetcode
body: <p>The question about Single Number II from leetcode is:</p>
  
  <p><strong>Given an array of integers, every element appears three times except for one. Find that single one.
  Note:
  Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?</strong></p>
  
  <p>Actually, I already found the solution from website, the solution is:</p>
  
  <pre class="lang-java prettyprint-override"><code>public int singleNumber(int[] A) {
      int one = 0, two = 0;
      for (int i = 0; i &lt; A.length; i++) {
          int one_ = (one ^ A[i]) &amp; ~two;
          int two_ = A[i] &amp; one | ~A[i] &amp; two;
          one = one_;
          two = two_;
      }
      return one;
  }
  </code></pre>
  
  <p>However, I do not know why this code can work and actually I do not know the way of thinking of this problem when I first saw it? Any help. thx!</p>