import java.util.ArrayList; public class Solution { ArrayList<Integer> list = new ArrayList<>(); public void Insert(Integer num) { if(list.isEmpty()){ list.add(num); }else{ int i = 0; while(i < list.size() && list.get(i) < num){ i++; } if(i == list.size()){ list.add(num); }else{ list.add(i, num); } } } public Double GetMedian() { int size = list.size(); int midSize = size / 2; if(size % 2 == 0){ return (double)(list.get(midSize - 1) + list.get(midSize)) / 2; }else{ return (double)(list.get((size - 1) / 2)); } }