Skip to content

Commit a02131c

Browse files
committed
2 parents f35d508 + 0031397 commit a02131c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

leetcode/hard/295_find_median_from_data_stream.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 295. Find Median from Data Stream
22

33
## Sort solution
4-
- Runtime: O(Nlog(N)) for addNum() and O(1) for findMedian()
4+
- Runtime: O(log(N)) for addNum() and O(1) for findMedian(), in total O(Nlog(N))
55
- Space: O(N)
66
- N = Number of elements in array
77

@@ -35,7 +35,7 @@ class MedianFinder:
3535
```
3636

3737
## Two Heap Solution
38-
- Runtime: O(Nlog(N)) for addNum() and O(1) for findMedian()
38+
- Runtime: O(log(N)) for addNum() and O(1) for findMedian(), in total O(Nlog(N))
3939
- Space: O(N)
4040
- N = Number of elements in array
4141

@@ -46,6 +46,8 @@ You can think of this as a divide and conquer approach.
4646
The only tricky part is to keep the two heaps balanced, balanced meaning the two heaps cannot differ in size by more than 1.
4747
Secondly, we need to keep the two heap property of smaller and larger sets.
4848

49+
Once these two properties are met, finding the median can be done by using the two values on top of the heap if both heap sizes are the same or taking the top value of the larger heap.
50+
4951
```
5052
class MedianFinder:
5153

0 commit comments

Comments
 (0)