Why my python solution Time Limit Exceeded ?

  • 0
        lenN = len(nums)
        if lenN < 2:return nums
        result_1 =[]
        def product(nums, k):
            lenN = len(nums)
            temp = 1
            for i in range(0, lenN):
                if i == k:
                temp *= nums[i]
            return temp
        for i in range(0,lenN):
        return result_1

  • 2

    It's clearly an O(n^2) algorithm. The problem requires that your code runs in O(n) time.

Log in to reply

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