Python3 1-line (sorting, 229ms, beats 92.5%, but why?)

  • 0

    I could hardly believe that such a brute force solution could pass and beat 90%.
    I expected 1000+ms but got a result of only 229ms. I was surprised, then I submitted the same code a couple of times, all the result are around 250.
    It has a shorter running time with a worse time complexity than others.

    return list(map(int, sorted(map(str, range(1, n + 1)))))

    In Python 2 this code (map(int, sorted(map(str, range(1, n + 1))))) uses 1529ms (beats 25.0%).
    Why so different running time? I have no idea. Could anyone explain?
    I know that some built-in functions in Python 3 returns Iterator objects instead of List objects. But I believe it could only accelerate the code a little, not a lot.

Log in to reply

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