# Moving Average from Data Stream (Leetcode 642)

Problem Link: <https://www.lintcode.com/problem/642/?fromId=201&_from=collection>

```python
class MovingAverage(object):
    """
    @param: size: An integer
    """
    def __init__(self, size):
        # do intialization if necessary
        self.q=[]
        self.k=size
        self.summ=0

    """
    @param: val: An integer
    @return:  
    """
    def next(self, val):
        # write your code here
        if(len(self.q)<self.k):
            self.q.append(val)
            self.summ+=val
            return self.summ/len(self.q)
        else:
            self.summ-=self.q[0]
            del self.q[0]
            self.q.append(val)
            self.summ+=val
            return self.summ/self.k
```
