class Solution {
private:
vector<double> nums;//记录当前已经插入数据
double mid;//记录中位数的位置
public:
Solution():mid(-0.5){
}
void Insert(int num) {
nums.push_back((double)num);
mid+=0.5;sort(nums.begin(),nums.end());
}
double GetMedian() {
double midnum;
string str = to_string(mid);
char ch = str[str.find_first_of('.')+1];
if(ch == '5'){
midnum = (nums[(int)(mid-0.5)]+nums[(int)(mid+0.5)])/2;
}else{
midnum = nums[mid];
}
return midnum;
}
};