Python - Two Sum:Why am I get "Time Exceeded Error"

  • 0

    Hello everyone, as titled and below is my Python code,
    I've passed the Run Code button but can not pass submit
    progress, it shows "Time Exceeded Error", can someone
    help me? Many thanks in advance.

        count = 0
        while count < len(nums):
            for k in range(len(nums)):
                if count + k + 1 < len(nums):
                    if (nums[count] + nums[count+k+1]) == target:
                        return [count, count+k+1]
            count += 1

  • 0

    this is O(n^2), try using dictionary(hashtable)

Log in to reply

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