其他分享
首页 > 其他分享> > leetcode165

leetcode165

作者:互联网

 1 class Solution:
 2     def compareVersion(self, version1: str, version2: str) -> int:
 3         ary1 = version1.split('.')
 4         ary2 = version2.split('.')
 5         n1,n2 = len(ary1),len(ary2)
 6         i,j = 0,0
 7         while i < n1 and j < n2:
 8             v1 = int(ary1[i])
 9             v2 = int(ary2[j])
10             if v1 < v2:
11                 return -1
12             elif v1 > v2:
13                 return 1
14             i += 1
15             j += 1
16         while i < n1:
17             v1 = int(ary1[i])
18             if v1 > 0:
19                 return 1
20             i += 1
21         while j < n2:
22             v2 = int(ary2[j])
23             if v2 > 0:
24                 return -1
25             j += 1
26         return 0

 

标签:return,int,leetcode165,ary1,v1,v2,ary2
来源: https://www.cnblogs.com/asenyang/p/12019707.html