Python solution beats 85% using list [] as queue


  • 0
    R
    def __init__(self, size):
            self.ls = []
            self.counter = 0
            self.size = size
            self.summe = 0
    
        def next(self, val):
            if self.counter < self.size: 
                self.counter += 1
            else:
                self.summe -= self.ls.pop(0)
            self.ls.append(val)
            self.summe += val
     
            return float(self.summe) / self.counter
    

Log in to reply
 

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