Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in Running Time on Leet Code

While practicing on Leet Code, I came up with my solution which was almost identical to the solution with the best running time. However, the difference in running time was significant.

So as a test I made a submission with the same exact code as the best solution and the running time increased rather decreasing.

Problem is to identify if a given list has any duplicates. Following is the best solution posted with running time 41ms. My submission with the same code has a running time of 82ms.

class Solution(object):
    def containsDuplicate(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """

        if nums == []:
            return False

        s = set(nums)
        return len(s) != len(nums)

https://leetcode.com/problems/contains-duplicate/description/

Since I just started with leet code and trying to understand if my solutions are optimum, I want to know how leet code calculates the running time and can we trust it to judge the performance of our solution.

Thanks in advance.

like image 370
Tanmay Gore Avatar asked Jul 02 '18 07:07

Tanmay Gore


1 Answers

40ms difference is way too low to take seriously. The python runtime takes about that long to fire up. Architectural changes LeetCode might have made to their testing suit, python interpreter, etc. are the most likely suspect for this performance disparity. After all, you submitted your solution today while the other solution was submitted a while ago.

like image 111
merlyn Avatar answered Oct 10 '22 08:10

merlyn