Why does it show Time limit exceeded? Python

  • 0
    class Solution:
    # @param num, a list of integers
    # @return an integer
    def majorityElement(self, num):
        l = len(num)
        for i in range(0, l):
            numb = num.count(num[i])
            if (numb >= l/2):
                a = i
                i = l
                return num[a]

    It works in the TextWrangler. Does it for the .count() function?

  • 0

    your solution will require O(n^2) time

Log in to reply

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