Class Solution

java.lang.Object
g0201_0300.s0260_single_number_iii.Solution

public class Solution extends Object
260 - Single Number III.<p>Medium</p> <p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an algorithm that runs in linear runtime complexity and uses only constant extra space.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,2,1,3,2,5]</p> <p><strong>Output:</strong> [3,5] **Explanation: ** [5, 3] is also a valid answer.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [-1,0]</p> <p><strong>Output:</strong> [-1,0]</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [0,1]</p> <p><strong>Output:</strong> [1,0]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= nums.length <= 3 * 10<sup>4</sup></code></li> <li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li> <li>Each integer in <code>nums</code> will appear twice, only two integers will appear once.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • singleNumber

      public int[] singleNumber(int[] nums)