C++ Code Easy Rosh


#1

Comment body goes here."int Solution::majorityElement(const vector &A) {
int n = A.size();

int y = floor(n/2);

//if(y == 1) return A[n-1];

vector<int> v;
v = A;

sort(v.begin(), v.end());

int c = 1, cmax = 0;

for(int i = 0; i < n; i++){
    if(v[i] == v[i+1]){
        c++;
    }
    if(c > y){
    return v[i];
    }
    if(v[i] != v[i+1])
    c = 1;
}
return A[n-1];

}
"