def maxProduct_error(self, A):
        """
        dp, collect number of negative number
        notice 0
        :param A: a list of int
        :return: int
        """
        if not A:
            return
        length = len(A)
        if length==1:
            return A[0]

        dp = [-1 for _ in xrange(length+1)]
        dp[length] = 0 # dummy
        for i in xrange(length-1, -1, -1):
            if A[i]<0:
                dp[i] = dp[i+1]+1
            elif A[i]==0:
                dp[i] = 0
            else:
                dp[i] = dp[i+1]

        global_max = -1<<32
        # cur = 1  # starting from 0, encountering problem [-2, 0, -1]
        # for ind, val in enumerate(A):
        #     cur *= val
        #     if cur<0 and dp[ind+1]<1 or cur==0:
        #             cur = 1
        #     global_max = max(global_max, cur)

        cur = 0  # starting from 0
        for ind, val in enumerate(A):
            if cur!=0:
                cur *= val
            else:
                cur = val

            if cur<0 and dp[ind+1]<1:
                cur = 0

            global_max = max(global_max, cur)

        return global_max
dataset/ETHPy150Open algorhythms/LeetCode/152 Maximum Product Subarray.py/Solution.maxProduct_error/original