/136. Single Number

136. Single Number

Easy
Arrays77.4% acceptance

Given a non-empty list of integers integer_list, where every element appears exactly twice except for one element that appears only once, return the element that appears only once. The solution must run in linear time and use only constant extra space.

Example 1

Input: [7, 3, 7]

Output: 3

Explanation: 3 appears only once, 7 appears twice.

Example 2

Input: [10, 10, 5, 5, 8]

Output: 8

Explanation: 8 appears only once, 10 and 5 appear twice.

Example 3

Input: [0, 1, 1]

Output: 0

Explanation: 0 appears only once, 1 appears twice.

Constraints

  • 1 <= len(integer_list) <= 30000
  • -30000 <= integer_list[i] <= 30000
  • All elements appear exactly twice except one element which appears only once.
  • Solution must run in O(n) time and use O(1) extra space.
Python (current runtime)

Case 1

Input: [6, 6, 9]

Expected: 9

Case 2

Input: [12, 15, 12, 15, 20]

Expected: 20

Case 3

Input: [100, 200, 100]

Expected: 200

Case 4

Input: [-5, -5, 0]

Expected: 0

Case 5

Input: [42]

Expected: 42