啊哈哈哈,挺简单的
数据流中的中位数
http://www.nowcoder.com/questionTerminal/9be0172896bd43948f8a32fb954e1be1
class Solution {
public:
vectora;
void Insert(int num)
{
a.insert(a.begin(),num);
}
double GetMedian() { sort (a.begin(),a.end()); if(a.size()%2==1) return (double)*(a.begin()+(a.size()-1)/2); else if(a.size()%2==0) return (double)(*(a.begin()+a.size()/2)+*(a.begin()+a.size()/2-1))/2; }
};