Easy snippet of code


#1

int Solution::majorityElement(const vector &A) {
int count = 0;
int ans;
for(int i:A){
if(count==0)
ans=i;
if(ans==i) count++;
else count --;
}
return ans;
}