#include <queue> #include <vector> class Solution { public: // priority_queue<double> v; vector<double> v; void Insert(int num) { v.emplace_back((double)num); } double GetMedian() { sort(v.begin(),v.end()); int len = v.size(); double ans = 0.0; // 如果元素个数是奇数 if(len%2) { ans = v[(len/2.0)]; } else { ans = (v[len/2-1]+v[len/2])/2.0; } return ans; } };