Why is my python code running to get a error "Time Limit Exceeded"?


  • 0
    D
    class Solution:
    # @param A, a list of integers
    # @return an integer
    def maxProduct(self, A):
        if 0 == len(A):
            return 0
        if 1 == len(A):
            return A[0]
        maxValue = A[0]
        for i in range(len(A)):
            value = 0x01
            for j in range(i, len(A)):
                if 0x00 == A[j]:
                    value = 0x01
                else:
                    value = value*A[j]
                if value > maxValue:
                    maxValue = value
        return maxValue

  • 0
    S

    My solution run as O(n)............


Log in to reply
 

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