Skip to content

Commit 60fb83e

Browse files
refactor 295
1 parent 4f3bbce commit 60fb83e

File tree

1 file changed

+6
-28
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+6
-28
lines changed

src/main/java/com/fishercoder/solutions/_295.java

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,16 @@
44
import java.util.PriorityQueue;
55
import java.util.Queue;
66

7-
/**
8-
* 295. Find Median from Data Stream
9-
*
10-
* Median is the middle value in an ordered integer list.
11-
* If the size of the list is even, there is no middle value.
12-
* So the median is the mean of the two middle value.
13-
14-
Examples:
15-
[2,3,4] , the median is 3
16-
17-
[2,3], the median is (2 + 3) / 2 = 2.5
18-
19-
Design a data structure that supports the following two operations:
20-
21-
void addNum(int num) - Add a integer number from the data stream to the data structure.
22-
double findMedian() - Return the median of all elements so far.
23-
For example:
24-
25-
addNum(1)
26-
addNum(2)
27-
findMedian() -> 1.5
28-
addNum(3)
29-
findMedian() -> 2
30-
*/
317
public class _295 {
32-
/**A few key points for both following solutions:
33-
*
8+
/**
9+
* A few key points for both following solutions:
10+
* <p>
3411
* 1. always keep one queue one element more than the other if the number is odd, offer into that one
3512
* first, then poll from that queue and offer into the other queue, then check whether that queue is smaller
3613
* in size than the other, if so, poll one from the other queue and offer it into this queue
37-
*
38-
* 2. only need to check whether this bigger queue size is greater than the other queue when returning.*/
14+
* <p>
15+
* 2. only need to check whether this bigger queue size is greater than the other queue when returning.
16+
*/
3917

4018
public static class Solution1 {
4119
public static class MedianFinder {

0 commit comments

Comments
 (0)