I made the same submission twice, it yields diff runtimes!


  • 0
    C

    I made this submission twice, once the runtime was 56ms (beats 58%) and another time it was 72ms (beats 19%). What's going on?

    class Solution(object):
            def majorityElement(self, nums):
                """
                :type nums: List[int]
                :rtype: int
                """
                counts = dict()
                for elem in nums:
                    counts[elem] = counts.get(elem, 0) + 1
                maximum = max(counts.values())
                for num, count in counts.iteritems():
                    if count == maximum:
                        return num

Log in to reply
 

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