Skip to content

Commit 288f512

Browse files
committed
Add template for solution with heap for Find Median from Data Stream
1 parent 246ac78 commit 288f512

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

find-median-from-data-stream/KwonNayeon.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- There will be at least one element in the data structure before calling findMedian.
55
- At most 5 * 10^4 calls will be made to addNum and findMedian.
66
7+
<Solution 1: 리스트 활용>
8+
79
Time Complexity:
810
- addNum(): O(nlogn)
911
- 매번 정렬하기 때문
@@ -41,3 +43,15 @@ def findMedian(self) -> float:
4143
mid2 = self.nums[n // 2]
4244
return (mid1 + mid2) / 2.0
4345

46+
"""
47+
<Solution 2: 힙 활용>
48+
49+
Time Complexity:
50+
51+
Space Complexity:
52+
53+
풀이방법:
54+
55+
"""
56+
from heapq import heappop, heappush
57+

0 commit comments

Comments
 (0)