Skip to content

Instantly share code, notes, and snippets.

@EfrainReyes
Created November 12, 2022 16:53
Show Gist options
  • Save EfrainReyes/0b08cd799b0fda024b61bcddc15cbb72 to your computer and use it in GitHub Desktop.
Save EfrainReyes/0b08cd799b0fda024b61bcddc15cbb72 to your computer and use it in GitHub Desktop.
295. Find Median from Data Stream
class MedianFinder:
def __init__(self):
self.data = []
def addNum(self, num: int) -> None:
bisect.insort(self.data, num)
def findMedian(self) -> float:
data_length = len(self.data)
mid_point = data_length // 2
if data_length % 2 == 0:
return (self.data[mid_point] + self.data[mid_point - 1] ) / 2
else:
return self.data[mid_point]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment