#260

Single Number III

pupil · 555 · lc medium +28 · verified · 70.4% accepted · 6,786 likes · top 79%

play →

Description

In the integer array nums, every element appears exactly twice except for two elements, each of which appears only once. Identify those two unique elements and return them in any order.

Your algorithm must run in linear time and use only constant extra space.

Example 1:

Input: nums = [1,2,1,3,2,5]
Output: [3,5]
Explanation: [5, 3] is also a valid answer.

Example 2:

Input: nums = [-1,0]
Output: [-1,0]

Example 3:

Input: nums = [0,1]
Output: [1,0]

Code

1
2
3