Java - Space complexity of this code : <p><strong>What is the space complexity of the code?</strong></p>

<p>I think it is O(1), since I don't technically store all the inputs into one array, i sort of split it up into 2 arrays. </p>

<p>This code is supposed to take an array with duplicates, and find the two numbers that don't have duplicates.</p>

<p><strong>My Code:</strong></p>

<pre><code>public int[] singleNumber(int[] nums) {
        int[] res = new int[2];
        HashSet&lt;Integer&gt; temp = new HashSet&lt;&gt;();
        HashSet&lt;Integer&gt; temp2 = new HashSet&lt;&gt;();

        for (int i : nums) {
            if (!temp.contains(i)) temp.add(i);
            else temp2.add(i);
        }

        for (int i : nums) {
            if (!temp2.contains(i)) {
                if (res[0] == 0) res[0] = i;
                else res[1] = i;
            }
        }

        return res;
    }
</code></pre>
