1336. Single Number II — Element Appears Three Times

MediumBit ManipulationBit ManipulationXORCounting

Given an array where every element appears exactly three times except for one element that appears once, find the element that appears once.

Input: A JSON object {"nums": [<integers>]} where all but one value appear three times.

Output: Return the element appearing exactly once.

Examples

Example 1
Input: {"nums":[2,2,3,2]}
Output: 3
Explanation: 2 appears three times, so 3 is the answer.
Example 2
Input: {"nums":[0,1,0,1,0,1,99]}
Output: 99
Explanation: 0 and 1 each appear three times -> 99.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →