AC Python code without extending the list


  • 0
    A

    Python solution without extending one of the two numbers

    class Solution:
    def compareVersion(self, version1, version2):
        v1=map(int,version1.split("."))
        v2=map(int,version2.split("."))
        for i in range(max(len(v1),len(v2))):
            v1p=v1[i] if i <len(v1) else 0
            v2p=v2[i] if i <len(v2) else 0
            if v1p>v2p:
                return 1
            elif v2p>v1p:
                return -1
        return 0

Log in to reply
 

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