-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompare Version Numbers.py
More file actions
33 lines (31 loc) · 906 Bytes
/
Copy pathCompare Version Numbers.py
File metadata and controls
33 lines (31 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
__author__ = 'Martin'
class Solution(object):
def compareVersion(self, version1, version2):
"""
:type version1: str
:type version2: str
:rtype: int
"""
str1 = version1.split(".");
str2 = version2.split(".");
i = 0
while i < len(str1) and i < len(str2):
if int(str1[i]) > int(str2[i]):
return 1
elif int(str1[i]) < int(str2[i]):
return -1
i += 1
amount = 0
if len(str1) > len(str2):
for i in str1[i:len(str1)]:
amount += int(i)
if amount != 0:
return 1
elif len(str1) < len(str2):
for i in str2[i:len(str2)]:
amount += int(i)
if amount != 0:
return -1
return 0
s = Solution()
print(s.compareVersion("1.0.0.0.1", "1"))