Add all the A tasks

This commit is contained in:
Ingy döt Net 2013-04-10 14:58:50 -07:00
parent 2dd7375f96
commit 051504d65b
1608 changed files with 18584 additions and 0 deletions

View file

@ -0,0 +1,10 @@
public static double median2(List<Double> list){
PriorityQueue<Double> pq = new PriorityQueue<Double>(list);
int n = list.size();
for (int i = 0; i < (n-1)/2; i++)
pq.poll(); // discard first half
if (n % 2 != 0) // odd length
return pq.poll();
else
return (pq.poll() + pq.poll()) / 2.0;
}