File tree Expand file tree Collapse file tree 1 file changed +6
-28
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +6
-28
lines changed Original file line number Diff line number Diff line change 4
4
import java .util .PriorityQueue ;
5
5
import java .util .Queue ;
6
6
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
- */
31
7
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>
34
11
* 1. always keep one queue one element more than the other if the number is odd, offer into that one
35
12
* first, then poll from that queue and offer into the other queue, then check whether that queue is smaller
36
13
* 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
+ */
39
17
40
18
public static class Solution1 {
41
19
public static class MedianFinder {
You can’t perform that action at this time.
0 commit comments