using System; using System.Collections.Generic; class Solution { List<int> list = new List<int>(); public void Insert(int num) { int left = 0; int right = list.Count - 1; if(right == -1) { list.Add(num); return; } int mid = 0; while(left <= right){ mid = (left + right) / 2; if(list[mid] < num) left = mid + 1; else if(list[mid] > num) right = mid - 1; else { left = mid; break; } } if(left > list.Count - 1) { list.Add(num); return; } list.Insert(left,num); } public double GetMedian() { int count = list.Count; double res; if((count & 1) == 1) return list[count >> 1]; else{ res = ((double)(list[count >> 1] + list[(count - 1) >> 1])) / 2; return res; } } }