165. Compare Version Numbers
贼简单,没什么技术含量
class Solution(object):
def compareVersion(self, version1, version2):
"""
:type version1: str
:type version2: str
:rtype: int
"""
version1 = version1.split('.')
version2 = version2.split('.')
m, n = len(version1), len(version2)
for i in range(min(m, n)):
if int(version1[i]) > int(version2[i]):
return 1
elif int(version1[i]) < int(version2[i]):
return -1
if m > n:
for i in range(n, m):
if int(version1[i]) > 0:
return 1
elif m < n:
for i in range(m, n):
if int(version2[i]) > 0 :
return -1
return 0
网友评论