好久没更新了, 上个新题吧。 求一个整数stream的sum, avg, median。 数据不断流入, 随时求sum, avg, median
1) consume(int value)
2 million
2) getSum()
3) getAverage()
4) getMedian()
1
2
-1
0
getSum => 1+2-1+0
4
10
20
-90
getAverage =
*/
import java.io.*;
import java.util.*;
import java.math.BigInteger;
import java.math.BigDecimal;
class Solution
{
private BigInteger sum = new BigInteger("0");
private double avg = 0;
private long n = 0;
private PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());
private PriorityQueue<Integer> minHeap = new PriorityQueue<>();
public static void main(String[] args)
{
Solution o = new Solution();
int[] arr = new int[]{-3,
版权声明:本文为xudli原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。