1 class Solution { 2 public: 3 vector<int> vec; 4 void Insert(int num) 5 { 6 vec.push_back(num); 7 } 8 9 double GetMedian() 10 { 11 sort(vec.begin(),vec.end()); 12 int size = vec.size(); 13 if(size % 2 == 0){ 14 return (double)(vec[size/2] + vec[size/2 - 1]) / 2; 15 }else{ 16 return (double)vec[size/2]; 17 } 18 } 19 20 };
原文:http://www.cnblogs.com/lca1826/p/6579369.html