Merge pull request #16501 from eugenp/fix-java-stream-integers-median-using-heap
Change int to double
This commit is contained in:
commit
fe759e41e4
|
@ -29,13 +29,13 @@ public class MedianOfIntegerStream {
|
|||
}
|
||||
|
||||
double getMedian() {
|
||||
int median;
|
||||
double median;
|
||||
if (minHeap.size() < maxHeap.size()) {
|
||||
median = maxHeap.peek();
|
||||
} else if (minHeap.size() > maxHeap.size()) {
|
||||
median = minHeap.peek();
|
||||
} else {
|
||||
median = (minHeap.peek() + maxHeap.peek()) / 2;
|
||||
median = (minHeap.peek() + maxHeap.peek()) / 2.0;
|
||||
}
|
||||
return median;
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ public class MedianOfIntegerStream2 {
|
|||
}
|
||||
|
||||
double getMedian() {
|
||||
int median;
|
||||
double median;
|
||||
if (minHeap.size() > maxHeap.size()) {
|
||||
median = minHeap.peek();
|
||||
} else {
|
||||
median = (minHeap.peek() + maxHeap.peek()) / 2;
|
||||
median = (minHeap.peek() + maxHeap.peek()) / 2.0;
|
||||
}
|
||||
return median;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue