Python 10 lines solution

  • 25
    def compareVersion(self, version1, version2):
            versions1 = [int(v) for v in version1.split(".")]
            versions2 = [int(v) for v in version2.split(".")]
            for i in range(max(len(versions1),len(versions2))):
                v1 = versions1[i] if i < len(versions1) else 0
                v2 = versions2[i] if i < len(versions2) else 0
                if v1 > v2:
                    return 1
                elif v1 < v2:
                    return -1;
            return 0;

  • 0

    i like your code. nice written.

Log in to reply

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