Why my codes cannot pass when submitting?


  • 0
    B
    class Solution
    {
    public:
        int singleNumber(vector<int>& nums)
        {
            int result = 0;
            int* count = new int[32];
            for(int i = 0; i < nums.size(); ++i)
            {
                for(int j = 0; j < 32; ++j)
                {
                    if((nums[i] & (1<<j)))
                    {
                        count[j]++;
                    }
                }
            }
    
            for(int j = 0; j < 32; ++j)
            {
                count[j] %= 3;
                if(count[j] != 0)
                {
                    result += (1<<j);
                }
            }
            return result;
        }
    };
    

    Test case: [0,0,0,5]
    When submitting, it cannot pass this test case with the unexpected answer 17. But when I run it by clicking "Run Code", it's 5 which is right.
    How can that happen?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.