straightforward python solution


  • 0
    G

    '''

    def compareVersion(self, version1, version2):
        v1=version1.split('.')
        v2=version2.split('.')
        l=min(len(v1), len(v2))
        for i in range(l):
            if int(v1[i])>int(v2[i]):
                return 1
            elif int(v1[i])<int(v2[i]):
                return -1
        if len(v1)==len(v2): 
            return 0
        else:
            if len(v1)>len(v2):
                v=v1
            else:
                v=v2
            for j in range(l, len(v)):
                if int(v[j])>0:
                    return 1 if v==v1 else -1
            return 0
    

    '''


Log in to reply
 

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