less than 1 minute read

You are given a list of integers nums where each integer occurs exactly three times except for one which occurs once. Return the lone integer.

Bonus: solve it in \(\mathcal{O}(1)\) space.

Constraints

  • n ≤ 100,000 where n is length of nums

https://binarysearch.com/problems/Lone-Integer

Examples

Example 1

Input

  • nums = [2, 2, 2, 9, 5, 5, 5]

Output

  • answer = 9

Example 2

Input

  • nums = [7, 1, 1, 1]

Output

  • answer = 7

Solution

Leave a comment