Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/com/blankj/hard/0295
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class MedianFinder {

List<Double> lst ;

public MedianFinder() {
lst = new ArrayList<>();
}

public void addNum(int num) {

double n = num*1.0;

/* for(int i=0;i<lst.size();i++)
{
if(lst.get(i)>n)
{
lst.add(i,n);
return;
}
} */
lst.add(n);
}

public double findMedian() {

Collections.sort(lst);

int sz= lst.size();
//System.out.println(lst.size());

if(sz%2!=0)
{
return lst.get(sz/2);
}
else
{
return (lst.get(sz/2)+lst.get((sz-1)/2))/2.0;
}

}
}