#-*- 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')
相关文章
- Java [Leetcode 165]Compare Version Numbers
- Leetcode2:Add Two Numbers@Python
- [LeetCode&Python] Problem 728. Self Dividing Numbers
- 【leetcode❤python】 165. Compare Version Numbers
- 165. Compare Version Numbers
- 【LeetCode】129. Sum Root to Leaf Numbers 解题报告(Python)
- 【LeetCode】633. Sum of Square Numbers 解题报告(python & Java & C++)
- 【LeetCode】357. Count Numbers with Unique Digits 解题报告(Python & C++)
- leetcode:Compare Version Numbers