/137. Find Unique Element Appearing Once Among Triplicates

137. Find Unique Element Appearing Once Among Triplicates

Medium
Arrays66.8% acceptance

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

Example 1

Input: [7,7,7,4,4,4,8]

Output: 8

Explanation: 8 appears once, all others appear three times.

Example 2

Input: [-5,-5,-5,12,12,12,0]

Output: 0

Explanation: 0 appears once, all others appear three times.

Example 3

Input: [100,100,100,200,200,200,300]

Output: 300

Explanation: 300 appears once, all others appear three times.

Constraints

  • 1 <= len(integer_list) <= 30000
  • -231 <= integer_list[i] <= 231 - 1
  • Every element in integer_list appears exactly three times except one element which appears once
Python (current runtime)

Case 1

Input: [9,9,9,11,11,11,15]

Expected: 15

Case 2

Input: [23,23,23,42,42,42,17]

Expected: 17

Case 3

Input: [-1,-1,-1,-2,-2,-2,5]

Expected: 5

Case 4

Input: [0,0,0,1,1,1,2]

Expected: 2