青铜A
class Solution { public: /** * * @param arr int整型vector * @return int整型 */ int Answerofjudge(vector<int>& a) { sort(a.begin(),a.end()); ll n=a.size(); double mid; if(n%2)mid=a[n/2]; else mid=0.5*(a[n/2]+a[n/2-1]); ll s=0; fi(i,0,n) { s+=a[i]; } double arv=1.*s/n; if(mid>arv)return 1; else return mid==arv?0:-1; } };
全部评论
(1) 回帖