/136. Single Number

136. Single Number

Easy
Arrays77.4% acceptance

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

Example 1

Input: [7, 3, 3]

Output: 7

Explanation: 7 appears once, 3 appears twice.

Example 2

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

Output: 8

Explanation: 8 appears once, others appear twice.

Example 3

Input: [42]

Output: 42

Explanation: Only one element, which is unique.

Constraints

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

Case 1

Input: [6, 9, 6]

Expected: 9

Case 2

Input: [12, 15, 12, 18, 15]

Expected: 18

Case 3

Input: [100, 200, 100]

Expected: 200

Case 4

Input: [0, 0, -1]

Expected: -1

Case 5

Input: [23, 23, 45, 45, 67]

Expected: 67