leetcode165-比较版本号

这个简单,下班前水的,不说了放代码吧

class Solution(object):
    def compareVersion(self, version1, version2):
        """
        :type version1: str
        :type version2: str
        :rtype: int
        """
        v1_list = version1.split('.')
        v2_list = version2.split('.')
        min_l = min(len(v1_list),len(v2_list))
        j = 0
        for i in range(min_l):
            if int(v1_list[i])>int(v2_list[i]):
                return 1
            elif int(v1_list[i]) len(v2_list):
            get = self.all_0(v1_list[min_l:])
            if get:
                return 0
            return 1
        elif len(v1_list) < len(v2_list):
            get = self.all_0(v2_list[min_l:])
            if get:
                return 0
            return -1
        else:
            return 0
    def all_0(self,other):
        for i in other:
            if int(i) != 0:
                return False
        return True

 

你可能感兴趣的:(LeetCode,Python,算法)