Leetcode 137 Solution

This article provides solution to leetcode question 137 (single-number-ii)

https://leetcode.com/problems/single-number-ii

Solution

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int res = 0;

        for (int t = 0; t < 32; t++)
        {
            int sum = 0;

            for (int i = 0; i < nums.size(); i++)
            {
                sum += (nums[i] >> t) & 1;
            }

            res |= (sum % 3) << t;
        }

        return res;
    }
};