If this solution kinda of cheating? Same time and memory complexity. Python solution beats 99%

  • 0
    import bisect
    class MedianFinder:
        def __init__(self):
            Initialize your data structure here.
            self.data = []
        def addNum(self, num):
            Adds a num into the data structure.
            :type num: int
            :rtype: void
            bisect.insort(self.data, num)
        def findMedian(self):
            Returns the median of current data stream
            :rtype: float
            if len(self.data) == 1:
                return self.data[0]
            if len(self.data) % 2 == 0:
                return (self.data[len(self.data)/2] + self.data[len(self.data)/2-1]) / 2.0
                return self.data[len(self.data)/2]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.