(int val)
| 9 | } |
| 10 | |
| 11 | public int add(int val) { |
| 12 | if (heap.size() < k) heap.offer(val); //for adding the values of the array |
| 13 | else if (val > heap.peek()) { |
| 14 | heap.poll(); //remove the top element |
| 15 | heap.add(val); //add the new element |
| 16 | } |
| 17 | return heap.peek(); |
| 18 | } |
| 19 | } |
no test coverage detected