Python solution


  • 0
    J
    class Solution(object):
        def compareVersion(self, version1, version2):
            """
            :type version1: str
            :type version2: str
            :rtype: int
            """
            v1 = map(lambda x: int(x), version1.split('.'))
            v2 = map(lambda x: int(x), version2.split('.'))
            
            
            v1 = v1 + [0] * (len(v2) - len(v1))
            v2 = v2 + [0] * (len(v1) - len(v2))
            
            for i in range(len(v1)):
                if v1[i] != v2[i]:
                    return 1 if v1[i] > v2[i] else -1
            
            return 0
    

Log in to reply
 

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