@@ -0,0 +1,1921 @@
+import heapq as hq%0A%0Aclass Solution:%0A    %22%22%22%0A    @param nums: A list of integers.%0A    @return: The median of numbers%0A    %22%22%22%0A    def medianII(self, nums):%0A        # write your code here%0A        if len(nums) %3C 2:%0A            return nums%0A        minheap = %5B%5D%0A        maxheap = %5B%5D%0A        sandwich = %5Bmaxheap, nums%5B0%5D, minheap%5D%0A        res = %5Bnums%5B0%5D%5D%0A        for i in range(1, len(nums)):%0A            print sandwich%0A            mid = sandwich%5B1%5D%0A            num = nums%5Bi%5D%0A            if len(maxheap) == len(minheap):%0A                if mid %3C= num:%0A                    hq.heappush(minheap, num)%0A                else:%0A                    if len(maxheap) == 0:%0A                        sandwich%5B1%5D = num%0A                    else:%0A                        top = -hq.heappop(maxheap)%0A                        if top %3C num:%0A                            sandwich%5B1%5D = num%0A                            hq.heappush(maxheap, -top)%0A                        else:%0A                            sandwich%5B1%5D = top%0A                            hq.heappush(maxheap, -num)%0A                    hq.heappush(minheap, mid)%0A            else:%0A                if mid %3C= num:%0A                    top = hq.heappop(minheap)%0A                    if top %3C num:%0A                        sandwich%5B1%5D = top%0A                        hq.heappush(minheap, num)%0A                    else:%0A                        sandwich%5B1%5D = num%0A                        hq.heappush(minheap, top)%0A                    hq.heappush(maxheap, -mid)%0A                    #maxheap.append(0)%0A                else:%0A                    hq.heappush(maxheap, -num)%0A                    #maxheap.append(0)%0A            res.append(sandwich%5B1%5D)%0A        return res%0A                    %0As = Solution()%0Atests = %5B%5D%0Atests.append(range(1,6))%0Atests.append(%5B4, 5, 1, 3, 2, 6, 0%5D)%0Atests.append(%5B2, 20, 100%5D)%0Atests.append(%5B2,20,13,18,15,8,3,5,4,25%5D)%0Atests.append(%5B5, -10, 4%5D)%0A%0Afor t in tests:%0A    print s.medianII(t)%0A

Create dataStreamMedian.py