本文共 551 字,大约阅读时间需要 1 分钟。
class Solution { public: vector v; void Insert(int num) { if (v.empty()) { v.push_back(num); } else { auto it = lower_bound(v.begin(), v.end(), num); v.insert(it, num); } } double GetMedian() { sort(v.begin(),v.end()); int sz=v.size(); // 奇数 安位与 if(sz & 1) return static_cast(v[sz>>1]); //偶数 else return static_cast (v[sz>>1]+v[(sz-1)>>1])/2; }};
转载地址:http://pnklf.baihongyu.com/