Why my program caused a runtime error?Thank you for your help.


  • 0
    L
    class Solution {
    public:
        int singleNumber(vector<int>& nums) {
            if(nums.empty()||nums.size()<=1)return nums[0];
            vector<int> r(sizeof(int)*8);
            for(int j=0;j<sizeof(int)*8;j++)
            {
                r[j]=0;
                for(int i=0;i<nums.size();i++)
                {
                    r[j]+=nums[i]&1;
                    nums[i]=(nums[i]>>1);
                }
                r[j]=r[j]%3;
            }
            int rtn=0;
            for(int k=sizeof(int)*8-1;k>=0;k++)
                {
                    rtn+=r[k];
                    rtn=(rtn<<1);
                }
            return rtn;
    }
    };
    

    As above is my program,please ignore its efficiency.I want to know why it's wrong.Thanks.


Log in to reply
 

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