I want to know what's the problem in my code


  • 0
    Z

    class MedianFinder:

    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.l=[]
        self.a=0
        
        
    
    def addNum(self, num):
        """
        Adds a num into the data structure.
        :type num: int
        :rtype: void
        """
        self.l.append(num)
        self.a+=num
        
    
    def findMedian(self):
        """
        Returns the median of current data stream
        :rtype: float
        """
        if len(self.l)%2!=0:
            return int(self.l[(len(self.l)+1)/2-1])
        else:
            return int(self.a/len(self.l))
    

    Your MedianFinder object will be instantiated and called as such:

    mf = MedianFinder()

    mf.addNum(1)

    mf.findMedian()


  • 0
    G

    Your data is not getting added in sorted form


Log in to reply
 

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