题解 | #数据流中的中位数#
数据流中的中位数
https://www.nowcoder.com/practice/9be0172896bd43948f8a32fb954e1be1
#include <vector> #include<algorithm> bool cmp_max(double x,double y){ return x < y; } class Solution { public: vector<double> arr; void Insert(int num) { arr.push_back(num); sort(arr.begin(),arr.end(),cmp_max); } double GetMedian() { if(arr.size()%2){ return arr[arr.size()/2]; }else{ return (arr[arr.size()/2] +arr[arr.size()/2-1])/2; } } };