<p>Given a <strong>non-empty</strong>&nbsp;array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>

<p>You must&nbsp;implement a solution with a linear runtime complexity and use&nbsp;only constant&nbsp;extra space.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums = [2,2,1]
<strong>Output:</strong> 1
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [4,1,2,1,2]
<strong>Output:</strong> 4
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> nums = [1]
<strong>Output:</strong> 1
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
	<li><code>-3 * 10<sup>4</sup> &lt;= nums[i] &lt;= 3 * 10<sup>4</sup></code></li>
	<li>Each element in the array appears twice except for one element which appears only once.</li>
</ul>

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int len = nums.size();
        int singleNum;
        int lp1, lp2, tInt;
        int lowest, pos;
        int count, curNum;

        if (len == 1)
            return nums[0];

        // sort the numbers
        for (lp1=0; lp1<len; lp1++) {
            pos = -1;
            lowest = nums[lp1];
            for (lp2=lp1; lp2<len; lp2++) {
                if (nums[lp2] < lowest) {
                    lowest = nums[lp2];
                    pos = lp2;
                }
            }

            // if lowest found, swap
            if (pos > 0) {
                tInt = nums[lp1];
                nums[lp1] = nums[pos];
                nums[pos] = tInt;
            }
        }

        // print array
        for (lp1=0; lp1<len; lp1++)
            cout << to_string(nums[lp1])+",";


        // loop through to find single digit
        curNum = nums[0];
        count = 1;
        for (lp1=1; lp1<len; lp1++) {
            if (nums[lp1] == curNum) {
                count++;
            } else {
                if (count == 1) {
                    return curNum;
                }
                count = 1;
                curNum = nums[lp1];
            }
        }
        return curNum;
    }
};
21900