Menu
CoddyTech

Single Number

You get a list nums in which every value appears exactly twice, except for one value that appears only once. Return the value that appears once.

Function

singleNumber(nums: integer-array) → integer
numsinteger-array
a list where every value appears twice except one
Returnsinteger
the value that appears only once

Constraints

  • 1 ≤ nums.length < 104
  • -104 ≤ nums[i] ≤ 104
  • Every value appears exactly twice, except one value that appears exactly once.

Examples

Input
nums = [8, 3, 8]
Output
3
Explanation
8 appears twice and 3 appears once, so the answer is 3.

lock icon+13 hidden tests on Submit

challenge icon

Follow-up

What if every value appeared three times except one? XOR alone no longer cancels the triples. Can you still find the single value in O(n) time and O(1) extra memory?

Reset code
def singleNumber(nums):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

nums = [8, 3, 8]

Expected

3