【leetcode❤python】 165. Compare Version Numbers

#-*- coding: UTF-8 -*-
class Solution(object):
    def compareVersion(self, version1, version2):
        """
        :type version1: str
        :type version2: str
        :rtype: int
        """
        versionl1=version1.split('.')
        versionl2=version2.split('.')
        n1,n2=len(versionl1),len(versionl2)
    
        if n1>n2:
            versionl2+=[0]*(n1-n2)
        else:versionl1+=[0]*(n2-n1)
        
        for i in range(len(versionl1)):
            
            if int(versionl1[i])>int(versionl2[i]):return 1
            elif int(versionl1[i])<int(versionl2[i]):return -1
        
        return 0

sol=Solution()
print sol.compareVersion('1', '1.1')

上一篇:【leetcode❤python】 8. String to Integer (atoi)


下一篇:【leetcode❤python】 168. Excel Sheet Column Title