Easy to understand Python solution

  • 0

    Easy to understand... but... this solution runs 59 ms, only beats 12% python submissions. Which part takes extra time ?? Thanks

    def compareVersion(self, version1, version2):
        l1 = [int(x) for x in version1.split('.')]
        l2 = [int(x) for x in version2.split('.')]
        if len(l1) < len(l2):
        if len(l1) > len(l2):
        i = 0
        while i < len(l1):
            if l1[i] > l2[i]:
                return 1
            elif l1[i] < l2[i]:
                return -1
                i += 1
        return 0

Log in to reply

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