Problem · Array
Single Number with Triplicates
Learn this problemProblem statement
Given a nonempty integer array nums, every value appears exactly three times except for one value that appears once. Return that single value.
Your solution must run in O(n) time and use O(1) auxiliary space.
Function
singleNumberTriplicates(nums: int[]) → intExamples
Example 1
nums = [2,2,3,2]return = 3Only 3 occurs once.
Example 2
nums = [0,1,0,1,0,1,99]return = 99Zero and one occur three times; 99 occurs once.
Constraints
1 <= nums.length <= 300001- Every value fits in a signed 32-bit integer.
- Exactly one value appears once; every other distinct value appears three times.