What is Output Limit Exceed Error?


  • 0
    L
        num.sort()
        result = []
        for i in range(len(num)-2):
            if i > 0 and num[i]==num[i-1]:
                pass
    
            j = i + 1
            k = len(num)-1
            while j < k:
             
                sum = num[j] + num[k] + num[i]
                if sum == 0:
                    result.append([num[i],num[j],num[k]])
                    j += 1
                    k -= 1
                    # check duplicate
                    while j < k and num[j]==num[j-1]:
                        j += 1
                    while j < k and num[k]==num[k+1]:
                        k -= 1
                        
                elif sum < 0:
                    j += 1
                else:
                    k -= 1
                    
        return result

  • 0
    I

    Try this case: [-1, -1, -1, 2]

    I got this problem just now.
    Just change the for i in range(len(num)-2) into while-loop.
    It seems that the 'i' cannot be changed inside the for-loop.


  • 0
    L

    hi, thank you so much for your help @illuz. In fact, I corrected this problem by using 'continue 'instead of 'pass' in the for loop. Thanks for your help anyway~


  • 0
    I

    Sorry, my code uses while num[i] == num[i + 1]: i += 1in the end of loop... I didn't see you use pass...


  • 0
    C

    Output Limit Exceed Error: I reckon this means your returned collection's size is too big. For example in this case your results have many duplicates.


Log in to reply
 

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