Single Number II

 https://www.interviewbit.com/problems/single-number-ii/
 
int Solution::singleNumber(const vector<int> &a) {
            if(a.size() == 0){
          return 0;
        }
            int ans=0;
        for(int i=0;i<32;i++){
            int count=0;
            for(int j=0;j<a.size();j++){
                if(a[j]&(1<<i)) count+=1;
            }
            if(count%3!=0) ans|=(1<<i);
        }
            return ans;
}


 

Comments

Popular posts from this blog

Perfect Peak of Array

Is Rectangle?

Sort array with squares!