title: Solving lonely int using map in c++
body: <p>Given an array of integers, where all elements but one occur twice, find the unique element.</p>
  <p>Example: Where <code>a = {1,2,3,4,3,2,1}</code>, the unique element is <code>4</code>.</p>
  <p>I realize using an XOR operation is the way to go with solving this problem but I thought it interesting to solve it using a map; however, I'm having a problem when the inputs are double digits: the answer defaults to null.</p>
  <p>My code:</p>
  <pre class="lang-cpp prettyprint-override"><code>using namespace std;
  
  int main(){
      
      vector&lt;int&gt; a = {34, 95, 34, 64, 45, 95, 16, 80, 80, 75, 3, 25, 75, 25, 31, 3, 64, 16, 31};
      
      //vector&lt;int&gt; a = {1, 2, 3, 4, 5, 1, 2, 3, 4};
      int lone_int = 0;
      map&lt;int, int&gt; int_freq; 
      for(int i = 0;i&lt;a.size();i++){
          int key = a[i];
          int_freq[key] = int_freq[key] + 1;
      }
      
      for(const auto &amp;x: int_freq){
          if(x.second == 1)lone_int = x.first;
          else lone_int = '/0';
          cout &lt;&lt; x.first &lt;&lt; &quot; &quot;  &lt;&lt; x.second &lt;&lt; endl;
      }
      cout &lt;&lt; lone_int &lt;&lt; endl;
  }
  </code></pre>